mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
trunk/branch integration: new PatternFormatter prefix
This commit is contained in:
parent
ddf9f8e7fd
commit
f88dacd2c3
@ -1,7 +1,7 @@
|
||||
//
|
||||
// PatternFormatter.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/PatternFormatter.cpp#16 $
|
||||
// $Id: //poco/1.4/Foundation/src/PatternFormatter.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
@ -36,6 +36,7 @@
|
||||
|
||||
#include "Poco/PatternFormatter.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTime.h"
|
||||
@ -73,31 +74,31 @@ PatternFormatter::~PatternFormatter()
|
||||
|
||||
inline void PatternFormatter::fmt(std::string& str, int value)
|
||||
{
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%d", value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%d", value);
|
||||
str.append(buffer);
|
||||
}
|
||||
|
||||
|
||||
inline void PatternFormatter::fmt(std::string& str, int value, int width)
|
||||
{
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%*d", width, value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%*d", width, value);
|
||||
str.append(buffer);
|
||||
}
|
||||
|
||||
|
||||
inline void PatternFormatter::fmt0(std::string& str, int value, int width)
|
||||
{
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%0*d", width, value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%0*d", width, value);
|
||||
str.append(buffer);
|
||||
}
|
||||
|
||||
|
||||
void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
{
|
||||
Timestamp timestamp = msg.getTime();
|
||||
Timestamp timestamp = msg.getTime();
|
||||
if (_localTime)
|
||||
{
|
||||
timestamp += Timezone::utcOffset()*Timestamp::resolution();
|
||||
@ -113,42 +114,45 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
if (++it != end)
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
case 's': text.append(msg.getSource()); break;
|
||||
case 't': text.append(msg.getText()); break;
|
||||
case 'l': fmt(text, (int) msg.getPriority()); break;
|
||||
case 'p': text.append(getPriorityName((int) msg.getPriority())); break;
|
||||
case 'q': text += getPriorityName((int) msg.getPriority()).at(0); break;
|
||||
case 'P': fmt(text, msg.getPid()); break;
|
||||
case 'T': text.append(msg.getThread()); break;
|
||||
case 'I': fmt(text, msg.getTid()); break;
|
||||
case 'N': text.append(Environment::nodeName()); break;
|
||||
case 'w': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3); break;
|
||||
case 'W': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]); break;
|
||||
case 'b': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3); break;
|
||||
case 'B': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]); break;
|
||||
case 'd': fmt0(text, dateTime.day(), 2); break;
|
||||
case 'e': fmt(text, dateTime.day()); break;
|
||||
case 'f': fmt(text, dateTime.day(), 2); break;
|
||||
case 'm': fmt0(text, dateTime.month(), 2); break;
|
||||
case 'n': fmt(text, dateTime.month()); break;
|
||||
case 'o': fmt(text, dateTime.month(), 2); break;
|
||||
case 'y': fmt0(text, dateTime.year() % 100, 2); break;
|
||||
case 'Y': fmt0(text, dateTime.year(), 4); break;
|
||||
case 'H': fmt0(text, dateTime.hour(), 2); break;
|
||||
case 'h': fmt0(text, dateTime.hourAMPM(), 2); break;
|
||||
case 'a': text.append(dateTime.isAM() ? "am" : "pm"); break;
|
||||
case 'A': text.append(dateTime.isAM() ? "AM" : "PM"); break;
|
||||
case 'M': fmt0(text, dateTime.minute(), 2); break;
|
||||
case 'S': fmt0(text, dateTime.second(), 2); break;
|
||||
case 'i': fmt0(text, dateTime.millisecond(), 3); break;
|
||||
case 'c': fmt(text, dateTime.millisecond()/100); break;
|
||||
case 'F': fmt0(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 '[':
|
||||
{
|
||||
++it;
|
||||
{
|
||||
case 's': text.append(msg.getSource()); break;
|
||||
case 't': text.append(msg.getText()); break;
|
||||
case 'l': NumberFormatter::append(text, (int) msg.getPriority()); break;
|
||||
case 'p': text.append(getPriorityName((int) msg.getPriority())); break;
|
||||
case 'q': text += getPriorityName((int) msg.getPriority()).at(0); break;
|
||||
case 'P': NumberFormatter::append(text, msg.getPid()); break;
|
||||
case 'T': text.append(msg.getThread()); break;
|
||||
case 'I': NumberFormatter::append(text, msg.getTid()); break;
|
||||
case 'N': text.append(Environment::nodeName()); break;
|
||||
case 'U': text.append(msg.getSourceFile() ? msg.getSourceFile() : ""); break;
|
||||
case 'u': NumberFormatter::append(text, msg.getSourceLine()); break;
|
||||
case 'w': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3); break;
|
||||
case 'W': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]); break;
|
||||
case 'b': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3); break;
|
||||
case 'B': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]); break;
|
||||
case 'd': NumberFormatter::append0(text, dateTime.day(), 2); break;
|
||||
case 'e': NumberFormatter::append(text, dateTime.day()); break;
|
||||
case 'f': NumberFormatter::append(text, dateTime.day(), 2); break;
|
||||
case 'm': NumberFormatter::append0(text, dateTime.month(), 2); break;
|
||||
case 'n': NumberFormatter::append(text, dateTime.month()); break;
|
||||
case 'o': NumberFormatter::append(text, dateTime.month(), 2); break;
|
||||
case 'y': NumberFormatter::append0(text, dateTime.year() % 100, 2); break;
|
||||
case 'Y': NumberFormatter::append0(text, dateTime.year(), 4); break;
|
||||
case 'H': NumberFormatter::append0(text, dateTime.hour(), 2); break;
|
||||
case 'h': NumberFormatter::append0(text, dateTime.hourAMPM(), 2); break;
|
||||
case 'a': text.append(dateTime.isAM() ? "am" : "pm"); break;
|
||||
case 'A': text.append(dateTime.isAM() ? "AM" : "PM"); break;
|
||||
case 'M': NumberFormatter::append0(text, dateTime.minute(), 2); break;
|
||||
case 'S': NumberFormatter::append0(text, dateTime.second(), 2); break;
|
||||
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 'E': NumberFormatter::append(text, msg.getTime().epochTime()); break;
|
||||
case '[':
|
||||
{
|
||||
++it;
|
||||
std::string prop;
|
||||
while (it != end && *it != ']') prop += *it++;
|
||||
if (it == end) --it;
|
||||
@ -193,10 +197,10 @@ std::string PatternFormatter::getProperty(const std::string& name) const
|
||||
}
|
||||
|
||||
|
||||
const std::string& PatternFormatter::getPriorityName(int prio)
|
||||
namespace
|
||||
{
|
||||
static std::string priorities[] =
|
||||
{
|
||||
static std::string priorities[] =
|
||||
{
|
||||
"",
|
||||
"Fatal",
|
||||
"Critical",
|
||||
@ -204,12 +208,16 @@ const std::string& PatternFormatter::getPriorityName(int prio)
|
||||
"Warning",
|
||||
"Notice",
|
||||
"Information",
|
||||
"Debug",
|
||||
"Trace"
|
||||
};
|
||||
"Debug",
|
||||
"Trace"
|
||||
};
|
||||
}
|
||||
|
||||
poco_assert (1 <= prio && prio <= 8);
|
||||
return priorities[prio];
|
||||
|
||||
const std::string& PatternFormatter::getPriorityName(int prio)
|
||||
{
|
||||
poco_assert (1 <= prio && prio <= 8);
|
||||
return priorities[prio];
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user