Ejemplo n.º 1
0
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));
  }
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
//----------------------------------------
//	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);
}