mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 16:37:13 +01:00
added %L modifier to PatternFormatter to switch to local time; some style fixes
This commit is contained in:
parent
c9590ff7d4
commit
a815e0a90e
@ -71,6 +71,7 @@ class Foundation_API PatternFormatter: public Formatter
|
||||
/// * %F - message date/time fractional seconds/microseconds (000000 - 999999)
|
||||
/// * %z - time zone differential in ISO 8601 format (Z or +NN.NN)
|
||||
/// * %Z - time zone differential in RFC format (GMT or +NNNN)
|
||||
/// * %L - convert time to local time (must be specified before any date/time specifier; does not itself output anything)
|
||||
/// * %E - epoch time (UTC, seconds since midnight, January 1, 1970)
|
||||
/// * %v[width] - the message source (%s) but text length is padded/cropped to 'width'
|
||||
/// * %[name] - the value of the message parameter with the given name
|
||||
|
@ -35,14 +35,14 @@ const std::string PatternFormatter::PROP_TIMES = "times";
|
||||
|
||||
PatternFormatter::PatternFormatter():
|
||||
_localTime(false),
|
||||
_localTimeOffset(0)
|
||||
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst()))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PatternFormatter::PatternFormatter(const std::string& format):
|
||||
_localTime(false),
|
||||
_localTimeOffset(0),
|
||||
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())),
|
||||
_pattern(format)
|
||||
{
|
||||
ParsePattern();
|
||||
@ -57,7 +57,8 @@ PatternFormatter::~PatternFormatter()
|
||||
void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
{
|
||||
Timestamp timestamp = msg.getTime();
|
||||
if (_localTime)
|
||||
bool localTime = _localTime;
|
||||
if (localTime)
|
||||
{
|
||||
timestamp += _localTimeOffset;
|
||||
}
|
||||
@ -99,8 +100,8 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
case 'i': NumberFormatter::append0(text, dateTime.millisecond(), 3); break;
|
||||
case 'c': NumberFormatter::append(text, dateTime.millisecond()/100); break;
|
||||
case 'F': NumberFormatter::append0(text, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); break;
|
||||
case 'z': text.append(DateTimeFormatter::tzdISO(_localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
|
||||
case 'Z': text.append(DateTimeFormatter::tzdRFC(_localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
|
||||
case 'z': text.append(DateTimeFormatter::tzdISO(localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
|
||||
case 'Z': text.append(DateTimeFormatter::tzdRFC(localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
|
||||
case 'E': NumberFormatter::append(text, msg.getTime().epochTime()); break;
|
||||
case 'v':
|
||||
if (ip->length > msg.getSource().length()) //append spaces
|
||||
@ -119,6 +120,14 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
{
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
if (!localTime)
|
||||
{
|
||||
localTime = true;
|
||||
timestamp += _localTimeOffset;
|
||||
dateTime = timestamp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,7 +137,7 @@ void PatternFormatter::ParsePattern()
|
||||
_patternActions.clear();
|
||||
std::string::const_iterator it = _pattern.begin();
|
||||
std::string::const_iterator end = _pattern.end();
|
||||
PatternAction end_act;
|
||||
PatternAction endAct;
|
||||
while (it != end)
|
||||
{
|
||||
if (*it == '%')
|
||||
@ -136,12 +145,12 @@ void PatternFormatter::ParsePattern()
|
||||
if (++it != end)
|
||||
{
|
||||
PatternAction act;
|
||||
act.prepend = end_act.prepend;
|
||||
end_act.prepend.clear();
|
||||
act.prepend = endAct.prepend;
|
||||
endAct.prepend.clear();
|
||||
|
||||
if(*it == '[')
|
||||
if (*it == '[')
|
||||
{
|
||||
act.key='x';
|
||||
act.key = 'x';
|
||||
++it;
|
||||
std::string prop;
|
||||
while (it != end && *it != ']') prop += *it++;
|
||||
@ -150,10 +159,10 @@ void PatternFormatter::ParsePattern()
|
||||
}
|
||||
else
|
||||
{
|
||||
act.key=*it;
|
||||
if ((it+1) != end && *(it+1) == '[')
|
||||
act.key = *it;
|
||||
if ((it + 1) != end && *(it + 1) == '[')
|
||||
{
|
||||
it+=2;
|
||||
it += 2;
|
||||
std::string number;
|
||||
while (it != end && *it != ']') number += *it++;
|
||||
if (it == end) --it;
|
||||
@ -161,7 +170,7 @@ void PatternFormatter::ParsePattern()
|
||||
{
|
||||
act.length = NumberParser::parse(number);
|
||||
}
|
||||
catch(...)
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -172,11 +181,13 @@ void PatternFormatter::ParsePattern()
|
||||
}
|
||||
else
|
||||
{
|
||||
end_act.prepend += *it++;
|
||||
endAct.prepend += *it++;
|
||||
}
|
||||
}
|
||||
if( end_act.prepend.size())
|
||||
_patternActions.push_back(end_act);
|
||||
if (endAct.prepend.size())
|
||||
{
|
||||
_patternActions.push_back(endAct);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -190,10 +201,11 @@ void PatternFormatter::setProperty(const std::string& name, const std::string& v
|
||||
else if (name == PROP_TIMES)
|
||||
{
|
||||
_localTime = (value == "local");
|
||||
_localTimeOffset = Timestamp::resolution()*( Timezone::utcOffset() + Timezone::dst() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Formatter::setProperty(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user