Does log4cplus support xml configuration file and

2019-04-14 17:42发布

问题:

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.