void logger_init( const std::string& path, LogPriority level, const std::string& format, const std::string& compress, const std::string& purgeCount) { if (_enableLogging) { _logFile = path; if (!_logDirectory.empty()) { // // Application override for the directory // std::string lfile = OSS::boost_file_name(_logFile); _logFile = operator/(_logDirectory, lfile); } AutoPtr<FileChannel> rotatedFileChannel(new FileChannel(OSS::boost_path(_logFile))); rotatedFileChannel->setProperty("rotation", "daily"); rotatedFileChannel->setProperty("archive", "timestamp"); rotatedFileChannel->setProperty("compress", compress); rotatedFileChannel->setProperty("purgeCount", purgeCount); AutoPtr<Formatter> formatter(new PatternFormatter(format.c_str())); AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, rotatedFileChannel)); _pLogger = &(Logger::create("OSS.logger", formattingChannel, level)); } }
ofLogger::ofLogger() { // code from Poco LogRotation sample Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel()); Poco::AutoPtr<Poco::Channel> consoleChannel(new Poco::ConsoleChannel()); Poco::AutoPtr<Poco::Channel> fileChannel(new Poco::FileChannel("sample.log")); Poco::AutoPtr<Poco::FileChannel> rotatedFileChannel(new Poco::FileChannel("rotated.log")); rotatedFileChannel->setProperty("rotation", "100"); rotatedFileChannel->setProperty("archive", "timestamp"); splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(fileChannel); splitterChannel->addChannel(rotatedFileChannel); Poco::AutoPtr<Poco::Formatter> formatter(new Poco::PatternFormatter("%t")); Poco::AutoPtr<Poco::Channel> formattingChannel(new Poco::FormattingChannel(formatter, splitterChannel)); logger = &Poco::Logger::create("Logger", formattingChannel, Poco::Message::PRIO_TRACE); }
//---------------------------------------- // PrepareConsoleLoggerWithRotatedLogFile //---------------------------------------- void PrepareConsoleLoggerWithRotatedLogFile( const std::string& name , const Poco::Util::MapConfiguration* config , int level=Poco::Message::PRIO_INFORMATION) { Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel); Poco::AutoPtr<Poco::Channel> consoleChannel(new Poco::ConsoleChannel); Poco::AutoPtr<Poco::FileChannel> rotatedFileChannel(new Poco::FileChannel); for(std::size_t i=0; i<kNumKeyDefaultValue; ++i) { rotatedFileChannel->setProperty(kKeyDefaultValue[i][0] , config->getString(kKeyDefaultValue[i][0], kKeyDefaultValue[i][1])); } splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(rotatedFileChannel); Poco::AutoPtr<Poco::Formatter> formatter(new Poco::PatternFormatter("%w %b %e %H:%M:%S.%i %Y: %t")); formatter->setProperty("times", "local"); Poco::AutoPtr<Poco::Channel> formattingChannel(new Poco::FormattingChannel(formatter, splitterChannel)); Poco::Logger::create(name, formattingChannel, level); }
static void __setupDefaultLogging(void) { const std::string logLevel = Poco::Environment::get("POTHOS_LOG_LEVEL", "notice"); const std::string logChannel = Poco::Environment::get("POTHOS_LOG_CHANNEL", "color"); const std::string logFile = Poco::Environment::get("POTHOS_LOG_FILE", "pothos.log"); const std::string logFomat = Poco::Environment::get("POTHOS_LOG_FORMAT", "%Y-%m-%d %H:%M:%S %s: %t"); const std::string logTimeZone = Poco::Environment::get("POTHOS_LOG_TIMEZONE", "local"); //local or UTC //set the logging level at the chosen root of logging inheritance Poco::Logger::get("").setLevel(logLevel); //create and set the channel with the type string specified Poco::AutoPtr<Poco::Channel> channel; if (logChannel == "null") channel = new Poco::NullChannel(); #if POCO_OS == POCO_OS_WINDOWS_NT else if (logChannel == "console") channel = new Poco::WindowsConsoleChannel(); else if (logChannel == "color") channel = new Poco::WindowsColorConsoleChannel(); #else else if (logChannel == "console") channel = new Poco::ConsoleChannel(); else if (logChannel == "color") channel = new Poco::ColorConsoleChannel(); #endif else if (logChannel == "file" and not logFile.empty()) { channel = new Poco::SimpleFileChannel(); channel->setProperty("path", logFile); } if (channel.isNull()) return; //setup formatting Poco::AutoPtr<Poco::Formatter> formatter(new Poco::PatternFormatter()); formatter->setProperty("pattern", logFomat); formatter->setProperty("times", logTimeZone); Poco::AutoPtr<Poco::Channel> formattingChannel(new Poco::FormattingChannel(formatter, channel)); Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel()); splitterChannel->addChannel(formattingChannel); Poco::Logger::get("").setChannel(splitterChannel); }
SDCLibrary2::SDCLibrary2() : WithLogger(OSELib::Log::BASE), initialized(false) { // set up the librarie's logger Poco::AutoPtr<Poco::ConsoleChannel> consoleChannel(new Poco::ConsoleChannel); Poco::AutoPtr<Poco::SimpleFileChannel> fileChannel(new Poco::SimpleFileChannel); Poco::AutoPtr<Poco::SplitterChannel> splitterChannel(new Poco::SplitterChannel); fileChannel->setProperty("path", "sdclib.log"); fileChannel->setProperty("rotation", "10 M"); splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(fileChannel); Poco::AutoPtr<Poco::PatternFormatter> patternFormatter(new Poco::PatternFormatter); patternFormatter->setProperty("pattern", "%q %H:%M:%S.%i %s:\n %t"); Poco::AutoPtr<Poco::FormattingChannel> formattingChannel(new Poco::FormattingChannel(patternFormatter, splitterChannel)); getLogger().setChannel(formattingChannel); // default ports chosen regarding to unlikely used ports: // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers }