PatternFormatter: add %O format specifier

This commit is contained in:
Günter Obiltschnig 2021-04-11 20:21:28 +02:00
parent f18ee10a3c
commit 53391151d1
3 changed files with 4 additions and 0 deletions

View File

@ -45,6 +45,7 @@ class Foundation_API PatternFormatter: public Formatter
/// * %I - message thread identifier (numeric)
/// * %N - node or host name
/// * %U - message source file path (empty string if not set)
/// * %O - message source file filename (empty string if not set)
/// * %u - message source line number (0 if not set)
/// * %w - message date/time abbreviated weekday (Mon, Tue, ...)
/// * %W - message date/time full weekday (Monday, Tuesday, ...)

View File

@ -23,6 +23,7 @@
#include "Poco/Environment.h"
#include "Poco/NumberParser.h"
#include "Poco/StringTokenizer.h"
#include "Poco/Path.h"
namespace Poco {
@ -81,6 +82,7 @@ void PatternFormatter::format(const Message& msg, std::string& text)
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 'O': text.append(msg.getSourceFile() ? Path(msg.getSourceFile()).getFileName() : ""); 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;

View File

@ -42,6 +42,7 @@ void PatternFormatterTest::testPatternFormatter()
msg.setThread("TestThread");
msg.setPriority(Message::PRIO_ERROR);
msg.setTime(DateTime(2005, 1, 1, 14, 30, 15, 500).timestamp());
msg.setSourceFile(__FILE__);
msg["testParam"] = "Test Parameter";
std::string result;