Log4j2 File Inclusion : and similar to Logback

后端 未结 2 590
南笙
南笙 2021-01-12 23:04

Does Log4j2 support file inclusion mechanism like Logback does ? This is for including parts of a configuration file from another file (containing appenders, loggers etc.)

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 23:43

    XInclude can be used, but isn't an ideal solution. When using XInclude the include files themselves have to define a single top level element such as Appenders/Loggers/Properties.

    Here's an example of how you could use it:

    
    
        
        
            jit %d %-5p [%t] %C{1.} - %m%n
        
    
        
        
        
    
    

    As an example include the log4j2-properties.xml could look like:

    
    
        
        %d %-5p [%t] %C{1.} - %m%n
    
    

    You can make XIncludes optional by using an empty "fallback" block. However in the latest version of log4j2 that is available this results in a warning message coming out of Xerces (since the DefaultErrorHandler is being used by log4j2).

    
        
    
    

提交回复
热议问题