Poco::Logger* CreateFileLogger(const string& file, const string& name) { FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c [%l][%p] %t")); pFCFile->setChannel(new FileChannel(file)); pFCFile->open(); Logger::root().setChannel(pFCFile); return &(Logger::get(name)); }
Poco::Logger* CreateConsoleLogger(const string& name) { FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t")); pFCConsole->setChannel(new ConsoleChannel); pFCConsole->open(); Logger::root().setChannel(pFCConsole); return &(Logger::get(name)); }
static PatternFormatter *getPatternFormatter() { getLogger(); FormattingChannel *fc = dynamic_cast<FormattingChannel*>(pocoLogger->getChannel()); assert(fc && "the first channel in the roadrunner logger should be a formatting channel"); PatternFormatter *pf = dynamic_cast<PatternFormatter*>(fc->getFormatter()); assert(pf && "formatter attached to pattern formatter is not a PatternFormatter"); return pf; }
static SplitterChannel* getSplitterChannel() { getLogger(); FormattingChannel *fc = dynamic_cast<FormattingChannel*>(pocoLogger->getChannel()); assert(fc && "the first channel in the roadrunner logger should be a formatting channel"); SplitterChannel *sc = dynamic_cast<SplitterChannel*>(fc->getChannel()); assert(sc && "could not get SplitterChannel from FormattingChannel"); return sc; }
void LoggingConfiguratorTest::testConfigurator() { static const std::string config = "logging.loggers.root.channel = c1\n" "logging.loggers.root.level = warning\n" "logging.loggers.l1.name = logger1\n" "logging.loggers.l1.channel.class = FileChannel\n" "logging.loggers.l1.channel.pattern = %s: [%p] %t\n" "logging.loggers.l1.channel.path = logfile.log\n" "logging.loggers.l1.level = information\n" "logging.loggers.l2.name = logger2\n" "logging.loggers.l2.channel.class = SplitterChannel\n" "logging.loggers.l2.channel.channel1 = c2\n" "logging.loggers.l2.channel.channel2 = c3\n" "logging.loggers.l2.level = debug\n" "logging.channels.c1.class = ConsoleChannel\n" "logging.channels.c1.formatter = f1\n" "logging.channels.c2.class = FileChannel\n" "logging.channels.c2.path = ${system.tempDir}/sample.log\n" "logging.channels.c2.formatter.class = PatternFormatter\n" "logging.channels.c2.formatter.pattern = %s: {%p} %t\n" "logging.channels.c3.class = ConsoleChannel\n" "logging.channels.c3.pattern = %s: [%p] %t\n" "logging.formatters.f1.class = PatternFormatter\n" "logging.formatters.f1.pattern = %s-[%p] %t\n" "logging.formatters.f1.times = UTC\n"; std::istringstream istr(config); AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr); LoggingConfigurator configurator; configurator.configure(pConfig); Logger& root = Logger::get(""); assert (root.getLevel() == Message::PRIO_WARNING); FormattingChannel* pFC = dynamic_cast<FormattingChannel*>(root.getChannel()); assertNotNull (pFC); #if defined(_WIN32) assertNotNull (dynamic_cast<Poco::WindowsConsoleChannel*>(pFC->getChannel())); #else assertNotNull (dynamic_cast<ConsoleChannel*>(pFC->getChannel())); #endif assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter())); assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s-[%p] %t"); Logger& logger1 = Logger::get("logger1"); assert (logger1.getLevel() == Message::PRIO_INFORMATION); pFC = dynamic_cast<FormattingChannel*>(logger1.getChannel()); assertNotNull (pFC); assertNotNull (dynamic_cast<FileChannel*>(pFC->getChannel())); assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter())); assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s: [%p] %t"); Logger& logger2 = Logger::get("logger2"); assert (logger2.getLevel() == Message::PRIO_DEBUG); assertNotNull (dynamic_cast<SplitterChannel*>(logger2.getChannel())); }
int main(int argc, char** argv) { // set up two channel chains - one to the // console and the other one to a log file. FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t")); pFCConsole->setChannel(new ConsoleChannel); pFCConsole->open(); FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s:%q:%t")); pFCFile->setChannel(new FileChannel("sample.log")); pFCFile->open(); // create two Logger objects - one for // each channel chain. Logger& consoleLogger = Logger::create("ConsoleLogger", pFCConsole, Message::PRIO_INFORMATION); Logger& fileLogger = Logger::create("FileLogger", pFCFile, Message::PRIO_WARNING); // log some messages consoleLogger.error("An error message"); fileLogger.error("An error message"); consoleLogger.warning("A warning message"); fileLogger.error("A warning message"); consoleLogger.information("An information message"); fileLogger.information("An information message"); poco_information(consoleLogger, "Another informational message"); poco_warning_f2(consoleLogger, "A warning message with arguments: %d, %d", 1, 2); Logger::get("ConsoleLogger").error("Another error message"); return 0; }
void CWtLoggerFactory::Init() { if (m_init) return; // set up two channel chains - one to the // console and the other one to a log file. FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t")); pFCConsole->setChannel(new ConsoleChannel); pFCConsole->open(); /* FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %N[%P]:%s:%q:%t")); pFCFile->setChannel(new FileChannel("wtOutput.log")); pFCFile->open(); */ // create two Logger objects - one for // each channel chain. //Logger::create("", pFCFile, Message::PRIO_INFORMATION); /* Logger& consoleLogger = Logger::create("ConsoleLogger", pFCConsole, Message::PRIO_INFORMATION); Logger& fileLogger = Logger::create("FileLogger", pFCFile, Message::PRIO_WARNING); // log some messages consoleLogger.error("An error message"); fileLogger.error("An error message"); consoleLogger.warning("A warning message"); fileLogger.error("A warning message"); consoleLogger.information("An information message"); fileLogger.information("An information message"); Logger::get("ConsoleLogger").error("Another error message"); */ m_init = true; }
CWtLoggerFactory& CWtLoggerFactory::Instance() { static CWtLoggerFactory* ll = NULL; if (!ll) { FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%i [%P]:%s:%p: %t")); pFCFile->setChannel(new FileChannel("wtOutput.log")); pFCFile->open(); /* FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t")); pFCConsole->setChannel(new ConsoleChannel); pFCConsole->open(); */ std::string tmp("bll"); ll = new CWtLoggerFactory(tmp,pFCFile, Poco::Message::PRIO_DEBUG); //ll->Init(); } return *ll; }