加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Poco Logging Framework中记录器层次结构的问题

发布时间:2020-12-16 05:04:45 所属栏目:百科 来源:网络整理
导读:使用Logging Framework时我遇到了一些问题.我有一个配置文件如下: # core channellogging.channels.c1.class = FileChannellogging.channels.c1.path = somePath/core.loglogging.channels.c1.archive = timestamplogging.channels.c1.times = utclogging.c
使用Logging Framework时我遇到了一些问题.我有一个配置文件如下:
# core channel
logging.channels.c1.class = FileChannel
logging.channels.c1.path = <somePath>/core.log
logging.channels.c1.archive = timestamp
logging.channels.c1.times = utc
logging.channels.c1.rotation = daily
logging.channels.c1.formatter.class = PatternFormatter
logging.channels.c1.formatter.pattern = %Y-%m-%d %H:%M:%S %s: [%p] %t

# core logger
logging.loggers.l1.name = core
logging.loggers.l1.level = information
logging.loggers.l1.channel = c1

我的程序使用Poco :: Util:ServerApplication框架,受益于子系统架构.我有多个子系统,每个子系统都存储一个Poco :: Logger对象的引用,该对象是使用Poco :: Logger :: get(“logger name”)方法获得的.我正在尝试使用日志层次结构,具有“核心”日志,如上面的配置文件中所示,作为我的日志记录层次结构的根.以下代码举例说明了我在每个susbsystem中所做的事情:

Subsystem1::Subsystem1() :
   Poco::Util::Subsystem(),logger_(Poco::Logger::get("core." + std::string(name()))),...

Subsystem2::Subsystem2() :
   Poco::Util::Subsystem(),...

这适用于日志记录.这很好,因为我从属性文件继承了配置,每个子系统都有一个不同的Poco :: Message源名称,这样就可以很容易地识别日志条目来自哪个子系统.

当我尝试更改记录器实例的属性时(例如,从Subsystem1的记录器),问题就出现了.例如,如果我更改了它的通道路径,则更改将传播到整个层次结构.以下代码演示了此问题:

Poco::Logger& subsystem1Logger = Poco::Logger::get("core.Subsystem1");
Poco::Logger& subsystem2Logger = Poco::Logger::get("core.Subsystem2");
subsystem1Logger.getChannel()->close(); //without this,the change to the channel's   path does nothing
subsystem1Logger.getChannel()->setProperty("path",<someOtherPath>/core2.log); // Ok,it's changed
poco_information(subsystem1Logger "some message"); // Ok,it logs to  <someOtherPath>/core2.log
poco_information(subsystem2Logger "some message"); // NOT OK,it also logs to  <someOtherPath>/core2.log instead of  <somePath>/core.log

我很困惑,因为它在Poco :: Logger类的头文件中声明“一旦创建了一个记录器并且它从其祖先继承了通道和级别,它就失去了与它的连接.所以改为记录器的级别或通道不会影响其后代“.

顺便说一句,我的根记录器(核心)也受到更改的影响.

我错过了什么吗?
谢谢.

Poco Library版本:1.5.1

解决方法

我认为你在记录器和频道之间感到困惑.

记录器
核心
Core.Subsystem1
Core.Subsystem2

都被连接到同一个通道c1,因为它们是创建时的Core副本.

它是您通过Logger.getChannel()函数更改的通道c1.

如果记录器连接到不同的通道,那么您的方法将起作用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读