#318: Logger local time doesn't automatically account for DST (PatternFormatter)

This commit is contained in:
Guenter Obiltschnig 2014-10-30 14:06:13 +01:00
parent abfb96877d
commit 721405d1fc
2 changed files with 17 additions and 17 deletions

View File

@ -121,10 +121,11 @@ protected:
/// Returns a string for the given priority value. /// Returns a string for the given priority value.
private: private:
struct PatternAction struct PatternAction
{ {
PatternAction(): key(0), length(0) {} PatternAction(): key(0), length(0)
{
}
char key; char key;
int length; int length;
@ -132,16 +133,14 @@ private:
std::string prepend; std::string prepend;
}; };
std::vector<PatternAction> _patternActions; void parsePattern();
bool _localTime;
Timestamp::TimeDiff _localTimeOffset;
std::string _pattern;
void ParsePattern();
/// Will parse the _pattern string into the vector of PatternActions, /// Will parse the _pattern string into the vector of PatternActions,
/// which contains the message key, any text that needs to be written first /// which contains the message key, any text that needs to be written first
/// a proprety in case of %[] and required length. /// a proprety in case of %[] and required length.
std::vector<PatternAction> _patternActions;
bool _localTime;
std::string _pattern;
}; };

View File

@ -34,18 +34,16 @@ const std::string PatternFormatter::PROP_TIMES = "times";
PatternFormatter::PatternFormatter(): PatternFormatter::PatternFormatter():
_localTime(false), _localTime(false)
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst()))
{ {
} }
PatternFormatter::PatternFormatter(const std::string& format): PatternFormatter::PatternFormatter(const std::string& format):
_localTime(false), _localTime(false),
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())),
_pattern(format) _pattern(format)
{ {
ParsePattern(); parsePattern();
} }
@ -60,7 +58,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
bool localTime = _localTime; bool localTime = _localTime;
if (localTime) if (localTime)
{ {
timestamp += _localTimeOffset; timestamp += Timezone::utcOffset()*Timestamp::resolution();
timestamp += Timezone::dst()*Timestamp::resolution();
} }
DateTime dateTime = timestamp; DateTime dateTime = timestamp;
for (std::vector<PatternAction>::iterator ip = _patternActions.begin(); ip != _patternActions.end(); ++ip) 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) if (!localTime)
{ {
localTime = true; localTime = true;
timestamp += _localTimeOffset; timestamp += Timezone::utcOffset()*Timestamp::resolution();
timestamp += Timezone::dst()*Timestamp::resolution();
dateTime = timestamp; dateTime = timestamp;
} }
break; break;
@ -132,7 +132,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
} }
} }
void PatternFormatter::ParsePattern()
void PatternFormatter::parsePattern()
{ {
_patternActions.clear(); _patternActions.clear();
std::string::const_iterator it = _pattern.begin(); 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) if (name == PROP_PATTERN)
{ {
_pattern = value; _pattern = value;
ParsePattern(); parsePattern();
} }
else if (name == PROP_TIMES) else if (name == PROP_TIMES)
{ {