mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
#318: Logger local time doesn't automatically account for DST (PatternFormatter)
This commit is contained in:
parent
abfb96877d
commit
721405d1fc
@ -121,10 +121,11 @@ protected:
|
||||
/// Returns a string for the given priority value.
|
||||
|
||||
private:
|
||||
|
||||
struct PatternAction
|
||||
{
|
||||
PatternAction(): key(0), length(0) {}
|
||||
PatternAction(): key(0), length(0)
|
||||
{
|
||||
}
|
||||
|
||||
char key;
|
||||
int length;
|
||||
@ -132,16 +133,14 @@ private:
|
||||
std::string prepend;
|
||||
};
|
||||
|
||||
std::vector<PatternAction> _patternActions;
|
||||
bool _localTime;
|
||||
Timestamp::TimeDiff _localTimeOffset;
|
||||
std::string _pattern;
|
||||
|
||||
|
||||
void ParsePattern();
|
||||
void parsePattern();
|
||||
/// Will parse the _pattern string into the vector of PatternActions,
|
||||
/// which contains the message key, any text that needs to be written first
|
||||
/// a proprety in case of %[] and required length.
|
||||
|
||||
std::vector<PatternAction> _patternActions;
|
||||
bool _localTime;
|
||||
std::string _pattern;
|
||||
};
|
||||
|
||||
|
||||
|
@ -34,18 +34,16 @@ const std::string PatternFormatter::PROP_TIMES = "times";
|
||||
|
||||
|
||||
PatternFormatter::PatternFormatter():
|
||||
_localTime(false),
|
||||
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst()))
|
||||
_localTime(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PatternFormatter::PatternFormatter(const std::string& format):
|
||||
_localTime(false),
|
||||
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())),
|
||||
_pattern(format)
|
||||
{
|
||||
ParsePattern();
|
||||
parsePattern();
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +58,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
bool localTime = _localTime;
|
||||
if (localTime)
|
||||
{
|
||||
timestamp += _localTimeOffset;
|
||||
timestamp += Timezone::utcOffset()*Timestamp::resolution();
|
||||
timestamp += Timezone::dst()*Timestamp::resolution();
|
||||
}
|
||||
DateTime dateTime = timestamp;
|
||||
for (std::vector<PatternAction>::iterator ip = _patternActions.begin(); ip != _patternActions.end(); ++ip)
|
||||
@ -124,7 +123,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
if (!localTime)
|
||||
{
|
||||
localTime = true;
|
||||
timestamp += _localTimeOffset;
|
||||
timestamp += Timezone::utcOffset()*Timestamp::resolution();
|
||||
timestamp += Timezone::dst()*Timestamp::resolution();
|
||||
dateTime = timestamp;
|
||||
}
|
||||
break;
|
||||
@ -132,7 +132,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
}
|
||||
}
|
||||
|
||||
void PatternFormatter::ParsePattern()
|
||||
|
||||
void PatternFormatter::parsePattern()
|
||||
{
|
||||
_patternActions.clear();
|
||||
std::string::const_iterator it = _pattern.begin();
|
||||
@ -196,7 +197,7 @@ void PatternFormatter::setProperty(const std::string& name, const std::string& v
|
||||
if (name == PROP_PATTERN)
|
||||
{
|
||||
_pattern = value;
|
||||
ParsePattern();
|
||||
parsePattern();
|
||||
}
|
||||
else if (name == PROP_TIMES)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user