Does log4cplus support xml configuration file and conditional logging?

十年热恋 提交于 2019-12-21 06:19:46

问题


I want to use MDC to set a context in my program, and then be able to set a filter in the config file to only show messages from a logger in a certain context.

MDC mdc; 
mdc.put("fieldName", "foo"); 
LOG4CPLUS_DEBUG(log, "ABC"); 

mdc.put("fieldName", "bar"); 
LOG4CPLUS_DEBUG(log, "XYZ"); 

I only want to print from log when "fieldName" is "bar", so only "XYZ" should be printed to my log.

In log4j this can be done using the XML format config file with filters. Can log4cplus use an XML config file? Can filters like this be set up in the XML log?

Also, is there a way to make log4cplus verbose, so I can see if it is finding my config file, and if it is able to read it, etc.

I am having trouble finding even one example of a log4cplus XML config file or how to read one.


回答1:


Log4cplus does not support any kind of XML configuration file. This is because it would require an XML parser and that is a pretty heavy dependency.

As for the filtering using MDC, there is currently no such filter. You would have to implement your own. See the Filter class.

You can set up log4cplus debugging from property file using log4cplus.configDebug=1. Or you can set the LOG4CPLUS_LOGLOG_DEBUGENABLED environment variable to 1. The former takes precedence over the latter.



来源:https://stackoverflow.com/questions/22815477/does-log4cplus-support-xml-configuration-file-and-conditional-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!