Added Test and new Pattern 'O' to only log the Filename not the full Path.

This commit is contained in:
Jan Kevin Dick 2020-02-19 13:56:52 +01:00
parent 76a89e0b3d
commit 13a89d4af4
2 changed files with 8 additions and 1 deletions

View File

@ -23,7 +23,7 @@
#include "Poco/Environment.h"
#include "Poco/NumberParser.h"
#include "Poco/StringTokenizer.h"
#include "Poco/Path.h"
namespace Poco {
@ -79,6 +79,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;
@ -91,6 +92,11 @@ void PatternFormatterTest::testPatternFormatter()
fmt.setProperty("pattern", "start %v[8] end");
fmt.format(msg, result);
assertTrue (result == "start stSource end");
result.clear();
fmt.setProperty("pattern", "%O");
fmt.format(msg, result);
assertTrue (result == "PatternFormatterTest.cpp");
}