Daemon: added formatting for console logger.

This commit is contained in:
Alexey Milovidov 2010-12-22 17:59:56 +00:00
parent fb1e8d8b75
commit e673533a0b

View File

@ -108,6 +108,7 @@ void Daemon::reloadConfiguration()
void Daemon::buildLoggers() void Daemon::buildLoggers()
{ {
Poco::ScopedRWLock lock(*this); Poco::ScopedRWLock lock(*this);
std::string format("%Y.%m.%d %H:%M:%S [ %I ] <%p> %s: %t");
try try
{ {
@ -120,9 +121,6 @@ void Daemon::buildLoggers()
// splitter // splitter
SplitterChannel *split = new SplitterChannel(); SplitterChannel *split = new SplitterChannel();
// format
std::string format("%Y.%m.%d %H:%M:%S [ %I ] <%p> %s: %t");
// set up two channel chains // set up two channel chains
PatternFormatter *pf = new PatternFormatter(format); PatternFormatter *pf = new PatternFormatter(format);
pf->setProperty("times", "local"); pf->setProperty("times", "local");
@ -157,23 +155,33 @@ void Daemon::buildLoggers()
split->open(); split->open();
logger().close(); logger().close();
logger().setChannel( split ); logger().setChannel(split);
} }
else else
{ {
// Выводим на консоль // Выводим на консоль
ConsoleChannel *file = new ConsoleChannel(); ConsoleChannel * file = new ConsoleChannel();
PatternFormatter * pf = new PatternFormatter(format);
pf->setProperty("times", "local");
FormattingChannel * log = new FormattingChannel(pf);
log->setChannel(file);
logger().close(); logger().close();
logger().setChannel( file ); logger().setChannel(log);
logger().warning("Logging to console"); logger().warning("Logging to console");
} }
} }
catch(...) catch(...)
{ {
// Выводим на консоль // Выводим на консоль
ConsoleChannel *file = new ConsoleChannel(); ConsoleChannel * file = new ConsoleChannel();
PatternFormatter * pf = new PatternFormatter(format);
pf->setProperty("times", "local");
FormattingChannel * log = new FormattingChannel(pf);
log->setChannel(file);
logger().close(); logger().close();
logger().setChannel( file ); logger().setChannel(log);
logger().warning("Can't log to file. Logging to console"); logger().warning("Can't log to file. Logging to console");
throw; throw;
} }