无法将splitterChannel与高级xml配置一起使用

Unable to use splitterChannel with advanced xml configuration with poco

本文关键字:配置 一起 xml 高级 splitterChannel      更新时间:2023-10-16

我想使用poco和它的配置文件配置一个高级记录器。我创建了这样一个config.xml文件:

<?xml version="1.0" ?>
<Application>
    <logging>
        <channels>
            <c1>
                <class>ColorConsoleChannel</class>
                <formatter>
                    <class>PatternFormatter</class>
                    <pattern>%Y-%m-%d %H:%M:%S : %s : [%p] : %t</pattern>
                </formatter>
                <traceColor>lightBlue</traceColor>
                <debugColor>blue</debugColor>
                <informationColor>green</informationColor>
                <noticeColor>green</noticeColor>
                <warningColor>yellow</warningColor>
                <errorColor>red</errorColor>
                <criticalColor>lightMagenta</criticalColor>
                <fatalColor>lightMagenta</fatalColor>       
            </c1>
            <c2>
                <class>FileChannel</class>
                <path>logs/traceApplication.log</path>
                <rotation>1 M</rotation>
                <archive>number</archive>
                <purgeCount>5</purgeCount>
                <formatter>
                    <class>PatternFormatter</class>
                    <pattern>%Y-%m-%d %H:%M:%S : %T : [%p] : %t</pattern>
                </formatter>
            </c2>
        </channels>
        <loggers>
            <consoleLogger>
                <channel>c1</channel>
                <level>information</level>
            </consoleLogger>
            <traceFileLogger>
                <channel>c2</channel>
                <level>trace</level>
            </traceFileLogger>
        </loggers>
        <channels>
            <cSplitter>
                <class>SplitterChannel</class>
                <channels>consoleLogger,traceFileLogger,mainFileLogger</channels>
            </cSplitter>
        </channels>
        <loggers>
            <root>
                <channel>cSplitter</channel>
                <level>trace</level>
            </root>
        </loggers>
    </logging>
</Application>

我使用Poco::Util::ServerApplication类,并在初始化方法中放入:

void CBS2AudioVideo::initialize(Poco::Util::Application& self)
{
    loadConfiguration("config.xml");
    Poco::Util::ServerApplication::initialize(self);
}

在添加splitterChannel之前,我的日志工作得很好,但是有了它,它就不再工作了。

我得到了错误信息:

未找到:日志通道:consoleLogger

我的目标是只有一个根记录器,当我使用它时,它以信息级别登录到控制台,并以跟踪级别登录到文件。

当我在channels. csplitter .channels中设置通道时,它可以工作,但所有通道都被记录到相同的级别。如果我使用日志配置幻灯片(http://pocoproject.org/slides/185-LoggingConfiguration.pdf),它们在logging.channels.splitter.channels属性区域中使用记录器而不是通道。所以我认为这是可能的。更多的Logger类也从Channel继承。

有人已经做过这样的工作或者有这样的想法吗?

我终于找到解决办法了。如果有人感兴趣,我把它贴在这里。

这个文件运行良好。

<?xml version="1.0" ?>
<Application>
    <logging>
        <channels>
            <cScreen>
                <class>ColorConsoleChannel</class>
                <formatter>
                    <class>PatternFormatter</class>
                    <pattern>%H:%M:%S : %T : [%p] : %t</pattern>
                </formatter>
                <traceColor>lightBlue</traceColor>
                <debugColor>blue</debugColor>
                <informationColor>white</informationColor>
                <noticeColor>green</noticeColor>
                <warningColor>yellow</warningColor>
                <errorColor>red</errorColor>
                <criticalColor>lightMagenta</criticalColor>
                <fatalColor>lightMagenta</fatalColor>       
            </cScreen>
            <cFile>
                <class>FileChannel</class>
                <path>logs/application.log</path>
                <rotation>1 M</rotation>
                <archive>number</archive>
                <purgeCount>5</purgeCount>
                <formatter>
                    <class>PatternFormatter</class>
                    <pattern>%H:%M:%S : %T : [%p] : %t</pattern>
                </formatter>
            </cFile>
        </channels>
        <loggers>
            <root>
                <name></name>
                <channel>cFile</channel>
                <level>trace</level>
            </root>
            <main>
                <name>main</name>
                <channel>cScreen</channel>
                <level>trace</level>
            </main>
        </loggers>
    </logging>

登录屏幕并在文件make:

Poco::Logger::get("main").trace(msg);

只记录到make

文件
Poco::Logger::get("").trace(msg);