是否可以基于Log4j中的附加程序为子记录器配置不同的日志级别?
例如,根父记录器对象名称为Services
。
其他子记录器是
Services.Connection
,Services.Connection.Queues
,Services.Connection.ObjectManager
现在我有2个日志附加程序,
其中一个以日志级别5(DEBUG)记录根记录器Services
的所有日志,并指向文件服务器。
另一个附加程序将子记录器Services.Connection
的所有日志记录为日志级别4(INFO),并指向access.log。现在,根据要求,第二记录器的子记录器Services.Connection.ObjectManager
将被静音。因此,对于记录器Services.Connection.ObjectManager
的日志级别设置为0, ,但这也会影响第1个附加程序,并且该记录器也被静音!
那么,基本上,如何在不影响配置中其他附加器的情况下使特定记录器的子记录器静音?
我已经使用一个配置文件来配置上述两个附加程序。配置文件如下所示:
############################################## ############
第一个Appender配置::
############################################## ############ ObjectName = Loggers:ServiceType = Logger,Name = Services,type = config
AppenderAdditive = true
LogLevel = 5ObjectName = Loggers:ServiceType = Logger,Name = Services,type = config,Appender = LogAppender
AppenderName = LogAppender
AppenderType = fileLogPattern = [%d {dd / MMM / yyyy HH:mm:ss}]%-10c {1}%-10p%m%n
FileName = server.log
ObjectName = Loggers:ServiceType = Logger,Name = Services,type = config,Appender = LogAppender ObjectName =记录器:ServiceType =记录器,名称=服务,类型=配置 ################################################ #########
第二个Appender配置
############################################## ############ ObjectName = Loggers:ServiceType = Logger,Name = Services.Connection,type = config
AppenderAdditive = true
LogLevel = 5ObjectName = Loggers:ServiceType = Logger,Name = Services.Connection,type = config,Appender = LogAppender
AppenderName = LogAppender
AppenderType = fileLogPattern = [%d {dd / MMM / yyyy HH:mm:ss}]%-10c {1}%-10p%m%n
FileName = access.log
ObjectName = Loggers:ServiceType = Logger,Name = Services,type = config,Appender = LogAppender ObjectName = Loggers:ServiceType = Logger,Name = Services,type = config
############################################## ############
记录器-静音配置
############################################## ############ ObjectName = Loggers:ServiceType = Logger,Name = Services.Connection.ObjectManager,type = config
AppenderAdditive = true
LogLevel = 0 ObjectName = Loggers:ServiceType = Logger,Name = Services.Connection.ObjectManager,type = config