mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
Added Test and new Pattern 'O' to only log the Filename not the full Path.
This commit is contained in:
parent
76a89e0b3d
commit
13a89d4af4
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user