Channel* LoggingConfigurator::createChannel(AbstractConfiguration* pConfig)
{
    AutoPtr<Channel> pChannel(LoggingFactory::defaultFactory().createChannel(pConfig->getString("class")));
    AutoPtr<Channel> pWrapper(pChannel);
    AbstractConfiguration::Keys props;
    pConfig->keys(props);
    for (AbstractConfiguration::Keys::const_iterator it = props.begin(); it != props.end(); ++it)
    {
        if (*it == "pattern")
        {
            AutoPtr<Formatter> pPatternFormatter(new PatternFormatter(pConfig->getString(*it)));
            pWrapper = new FormattingChannel(pPatternFormatter, pChannel);
        }
        else if (*it == "formatter")
        {
            AutoPtr<FormattingChannel> pFormattingChannel(new FormattingChannel(0, pChannel));
            if (pConfig->hasProperty("formatter.class"))
            {
                AutoPtr<AbstractConfiguration> pFormatterConfig(pConfig->createView(*it));
                AutoPtr<Formatter> pFormatter(createFormatter(pFormatterConfig));
                pFormattingChannel->setFormatter(pFormatter);
            }
            else pFormattingChannel->setProperty(*it, pConfig->getString(*it));
#if defined(__GNUC__) && __GNUC__ < 3
            pWrapper = pFormattingChannel.duplicate();
#else
            pWrapper = pFormattingChannel;
#endif
        }
    }
    return pWrapper.duplicate();
}
void LoggingConfigurator::configureFormatters(AbstractConfiguration* pConfig)
{
    AbstractConfiguration::Keys formatters;
    pConfig->keys(formatters);
    for (AbstractConfiguration::Keys::const_iterator it = formatters.begin(); it != formatters.end(); ++it)
    {
        AutoPtr<AbstractConfiguration> pFormatterConfig(pConfig->createView(*it));
        AutoPtr<Formatter> pFormatter(createFormatter(pFormatterConfig));
        LoggingRegistry::defaultRegistry().registerFormatter(*it, pFormatter);
    }
}
Formatter* LoggingConfigurator::createFormatter(AbstractConfiguration* pConfig)
{
    AutoPtr<Formatter> pFormatter(LoggingFactory::defaultFactory().createFormatter(pConfig->getString("class")));
    AbstractConfiguration::Keys props;
    pConfig->keys(props);
    for (AbstractConfiguration::Keys::const_iterator it = props.begin(); it != props.end(); ++it)
    {
        if (*it != "class")
            pFormatter->setProperty(*it, pConfig->getString(*it));
    }
    return pFormatter.duplicate();
}
Example #4
0
void Plugin::setupLogger()
{
    AutoPtr<FileChannel>            pChannel(new FileChannel);
    AutoPtr<ConsoleChannel>         cConsole(new ConsoleChannel);
    AutoPtr<SplitterChannel>        pSplitter(new SplitterChannel);
    AutoPtr<PatternFormatter>       pFormatter(new PatternFormatter);
    pFormatter->setProperty("pattern", "%Y-%m-%d %H:%M:%S [%p]: %t");
    pFormatter->setProperty("times", "local");
    // We will uncomment this later. Maybe. This preventing from writing into log files
    //pSplitter->addChannel(pChannel);
    pSplitter->addChannel(cConsole);
    //pChannel->setProperty("path", "/var/log/git-keshig.log");
    //pChannel->setProperty("rotation", "5 M");
    AutoPtr<FormattingChannel> pFormatChannel(new FormattingChannel(pFormatter, pSplitter));
    Logger& log = Application::instance().logger();
    log.setLevel(Poco::Message::PRIO_DEBUG);
    log.setChannel(pFormatChannel);
}