使用log4cxx在C++中记录特定的类

Using log4cxx for logging a particular class in C++

本文关键字:记录 log4cxx C++ 使用      更新时间:2023-10-16

以下是我在项目中使用的示例log4cxx配置文件

# Set root logger level to INFO and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss.SSS} %X{pname}:%X{pid} %-5p %l- %m%n
log4j.appender.A1.serverFileAppender=org.apache.log4j.RollingFileAppender
# Tweak the timestamp format so that it sorts easier
log4j.appender.A1.serverFileAppender.fileName=/tmp/client_cpp.log

当前,rootLogger被设置为INFO。有没有办法将其配置为只在某些.cpp文件中记录DEBUG消息?例如,我有一个Consumer.cpp文件,其中包含一些DEBUG级别的日志消息。如何配置它,使其仅记录该文件中的DEBUG消息?我在这里浏览了教程,但没有提交相关信息。

我通过在log4cxx.conf文件-中添加以下行解决了这个问题

log4j.category.ProducerImpl=DEBUG