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; }
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)); }
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)); }
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; }