#2989: setting priorityNames property on PatternFormatter has no effect

This commit is contained in:
Günter Obiltschnig 2021-04-11 17:26:13 +02:00
parent f1c4c9a27d
commit c5ee4b1184
3 changed files with 24 additions and 33 deletions

View File

@ -143,6 +143,8 @@ private:
void parsePriorityNames();
static const std::string DEFAULT_PRIORITY_NAMES;
std::vector<PatternAction> _patternActions;
bool _localTime;
std::string _pattern;

View File

@ -31,10 +31,11 @@ namespace Poco {
const std::string PatternFormatter::PROP_PATTERN = "pattern";
const std::string PatternFormatter::PROP_TIMES = "times";
const std::string PatternFormatter::PROP_PRIORITY_NAMES = "priorityNames";
const std::string PatternFormatter::DEFAULT_PRIORITY_NAMES = "Fatal,Critical,Error,Warning,Notice,Information,Debug,Trace";
PatternFormatter::PatternFormatter():
_localTime(false)
_localTime(false),
_priorityNames(DEFAULT_PRIORITY_NAMES)
{
parsePriorityNames();
}
@ -42,7 +43,8 @@ PatternFormatter::PatternFormatter():
PatternFormatter::PatternFormatter(const std::string& format):
_localTime(false),
_pattern(format)
_pattern(format),
_priorityNames(DEFAULT_PRIORITY_NAMES)
{
parsePriorityNames();
parsePattern();
@ -230,48 +232,24 @@ std::string PatternFormatter::getProperty(const std::string& name) const
}
namespace
{
static std::string priorities[] =
{
"",
"Fatal",
"Critical",
"Error",
"Warning",
"Notice",
"Information",
"Debug",
"Trace"
};
}
void PatternFormatter::parsePriorityNames()
{
for (int i = 0; i <= 8; i++)
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
if (st.count() == 8)
{
_priorities[i] = priorities[i];
}
if (!_priorityNames.empty())
{
StringTokenizer st(_priorityNames, ",;", StringTokenizer::TOK_TRIM);
if (st.count() == 8)
for (int i = 1; i <= 8; i++)
{
for (int i = 1; i <= 8; i++)
{
_priorities[i] = st[i - 1];
}
_priorities[i] = st[i - 1];
}
else throw Poco::SyntaxException("priorityNames property must specify a comma-separated list of 8 property names");
}
else throw Poco::SyntaxException("priorityNames property must specify a comma-separated list of 8 property names");
}
const std::string& PatternFormatter::getPriorityName(int prio)
{
poco_assert (1 <= prio && prio <= 8);
return priorities[prio];
return _priorities[prio];
}

View File

@ -91,6 +91,17 @@ 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");
result.clear();
fmt.setProperty("priorityNames", "FATAL,CRITICAL,SPECIAL_ERROR_NAME,WARN,NOTICE,INFO,DEBUG,TRACE");
fmt.setProperty("pattern", "%p");
fmt.format(msg, result);
assertTrue (result == "SPECIAL_ERROR_NAME");
}