Poco从SplitterChannel获取记录器通道

时间:2019-07-09 09:23:02

标签: c++ logging poco-libraries

在我的应用程序中,我从XML配置文件加载了Logger的配置。这很好。对于我的记录仪,我必须配置通道。一个记录到文件,另一个记录到控制台。

使用logger.getChannel(),我可以获得SplitterChannel。但是我需要访问包含的频道。但是我没有找到从SplitterChannel

中提取2个频道的方法

这是加载日志记录配置的代码:

if (Poco::File{ configPath }.exists()) {
    try {
        Poco::AutoPtr<Poco::Util::AbstractConfiguration> loggingConfig{ new Poco::Util::XMLConfiguration{configPath.toString()} };
        Poco::Util::LoggingConfigurator logConf;
        logConf.configure(loggingConfig);
        auto logFilePath = loggingConfig->getString("logging.channels.c1.path");

        Poco::File logFile{ Poco::Path{logFilePath}.parent() };
        if (!logFile.path().empty() && !logFile.exists()) {
            logFile.createDirectories();
        }
        Poco::AutoPtr<Poco::Util::AbstractConfiguration> linesyncView{ loggingConfig->createView("LineSync") };
        displayThreadNames = linesyncView->getBool("displayThreadNames", false);
    } catch (const Poco::Exception&) {
        poco_error(logger, "Could not load Config File");
    }
}

这是“日志记录配置”:

<config>
<logging>
    <channels>
        <c1>
            <class>FileChannel</class>
            <path>C:\Log\log.log</path>
            <rotation>100 M</rotation>
            <archive>timestamp</archive>
            <compress>true</compress>
            <formatter>
                <class>PatternFormatter</class>
                <pattern>%L%d-%m-%Y;%H:%M:%S;%s(%U [%u] );[%p %I];%t</pattern>
            </formatter>
        </c1>
        <c2>
            <class>ColorConsoleChannel</class>
            <pattern>%s(%U [%u]): [%p %I] %t</pattern>
        </c2>
        <splitter>
            <class>SplitterChannel</class>
            <channels>c1,c2</channels>
        </splitter>
    </channels>
    <loggers>
        <root>
            <channel>splitter</channel>
            <level>information</level>
        </root>
    </loggers>
</logging>
</config>

0 个答案:

没有答案
相关问题