mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-04 01:27:11 +02: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)
|
/// * %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 ISO 8601 format (Z or +NN.NN)
|
||||||
/// * %Z - time zone differential in RFC format (GMT or +NNNN)
|
/// * %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)
|
/// * %E - epoch time (UTC, seconds since midnight, January 1, 1970)
|
||||||
/// * %v[width] - the message source (%s) but text length is padded/cropped to 'width'
|
/// * %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
|
/// * %[name] - the value of the message parameter with the given name
|
||||||
|
@ -35,14 +35,14 @@ const std::string PatternFormatter::PROP_TIMES = "times";
|
|||||||
|
|
||||||
PatternFormatter::PatternFormatter():
|
PatternFormatter::PatternFormatter():
|
||||||
_localTime(false),
|
_localTime(false),
|
||||||
_localTimeOffset(0)
|
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PatternFormatter::PatternFormatter(const std::string& format):
|
PatternFormatter::PatternFormatter(const std::string& format):
|
||||||
_localTime(false),
|
_localTime(false),
|
||||||
_localTimeOffset(0),
|
_localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())),
|
||||||
_pattern(format)
|
_pattern(format)
|
||||||
{
|
{
|
||||||
ParsePattern();
|
ParsePattern();
|
||||||
@ -57,7 +57,8 @@ PatternFormatter::~PatternFormatter()
|
|||||||
void PatternFormatter::format(const Message& msg, std::string& text)
|
void PatternFormatter::format(const Message& msg, std::string& text)
|
||||||
{
|
{
|
||||||
Timestamp timestamp = msg.getTime();
|
Timestamp timestamp = msg.getTime();
|
||||||
if (_localTime)
|
bool localTime = _localTime;
|
||||||
|
if (localTime)
|
||||||
{
|
{
|
||||||
timestamp += _localTimeOffset;
|
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 'i': NumberFormatter::append0(text, dateTime.millisecond(), 3); break;
|
||||||
case 'c': NumberFormatter::append(text, dateTime.millisecond()/100); break;
|
case 'c': NumberFormatter::append(text, dateTime.millisecond()/100); break;
|
||||||
case 'F': NumberFormatter::append0(text, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); 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::tzdISO(localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
|
||||||
case 'Z': text.append(DateTimeFormatter::tzdRFC(_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 'E': NumberFormatter::append(text, msg.getTime().epochTime()); break;
|
||||||
case 'v':
|
case 'v':
|
||||||
if (ip->length > msg.getSource().length()) //append spaces
|
if (ip->length > msg.getSource().length()) //append spaces
|
||||||
@ -119,6 +120,14 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'L':
|
||||||
|
if (!localTime)
|
||||||
|
{
|
||||||
|
localTime = true;
|
||||||
|
timestamp += _localTimeOffset;
|
||||||
|
dateTime = timestamp;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +137,7 @@ void PatternFormatter::ParsePattern()
|
|||||||
_patternActions.clear();
|
_patternActions.clear();
|
||||||
std::string::const_iterator it = _pattern.begin();
|
std::string::const_iterator it = _pattern.begin();
|
||||||
std::string::const_iterator end = _pattern.end();
|
std::string::const_iterator end = _pattern.end();
|
||||||
PatternAction end_act;
|
PatternAction endAct;
|
||||||
while (it != end)
|
while (it != end)
|
||||||
{
|
{
|
||||||
if (*it == '%')
|
if (*it == '%')
|
||||||
@ -136,12 +145,12 @@ void PatternFormatter::ParsePattern()
|
|||||||
if (++it != end)
|
if (++it != end)
|
||||||
{
|
{
|
||||||
PatternAction act;
|
PatternAction act;
|
||||||
act.prepend = end_act.prepend;
|
act.prepend = endAct.prepend;
|
||||||
end_act.prepend.clear();
|
endAct.prepend.clear();
|
||||||
|
|
||||||
if(*it == '[')
|
if (*it == '[')
|
||||||
{
|
{
|
||||||
act.key='x';
|
act.key = 'x';
|
||||||
++it;
|
++it;
|
||||||
std::string prop;
|
std::string prop;
|
||||||
while (it != end && *it != ']') prop += *it++;
|
while (it != end && *it != ']') prop += *it++;
|
||||||
@ -150,10 +159,10 @@ void PatternFormatter::ParsePattern()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
act.key=*it;
|
act.key = *it;
|
||||||
if ((it+1) != end && *(it+1) == '[')
|
if ((it + 1) != end && *(it + 1) == '[')
|
||||||
{
|
{
|
||||||
it+=2;
|
it += 2;
|
||||||
std::string number;
|
std::string number;
|
||||||
while (it != end && *it != ']') number += *it++;
|
while (it != end && *it != ']') number += *it++;
|
||||||
if (it == end) --it;
|
if (it == end) --it;
|
||||||
@ -161,7 +170,7 @@ void PatternFormatter::ParsePattern()
|
|||||||
{
|
{
|
||||||
act.length = NumberParser::parse(number);
|
act.length = NumberParser::parse(number);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch (...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,11 +181,13 @@ void PatternFormatter::ParsePattern()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
end_act.prepend += *it++;
|
endAct.prepend += *it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( end_act.prepend.size())
|
if (endAct.prepend.size())
|
||||||
_patternActions.push_back(end_act);
|
{
|
||||||
|
_patternActions.push_back(endAct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,10 +201,11 @@ void PatternFormatter::setProperty(const std::string& name, const std::string& v
|
|||||||
else if (name == PROP_TIMES)
|
else if (name == PROP_TIMES)
|
||||||
{
|
{
|
||||||
_localTime = (value == "local");
|
_localTime = (value == "local");
|
||||||
_localTimeOffset = Timestamp::resolution()*( Timezone::utcOffset() + Timezone::dst() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Formatter::setProperty(name, value);
|
Formatter::setProperty(name, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user