Log4J Custom Fields

后端 未结 3 1685
再見小時候
再見小時候 2020-12-15 06:08

Introduction:

I\'m trying to get additional fields to log with log4j, and its working but only when I create an appender in code and not in the log4j.properties

3条回答
  •  既然无缘
    2020-12-15 07:07

    I'm not sure that you will achieve this with properties configuration, but I think you can do this with XML, which gives you a lot of customization options:

    
    
    
      
        
        
          
        
      
    
      
        
        
      
    
      
        
        
        
      
    
    
    

    You will need to define setters on AppServerLoggerFactory for server, component and version. Also, read log4j.dtd on general layout of xml configuration file.

    Save this file as log4j.xml and define -Dlog4j.configuration=/path/to/log4j.xml in your startup script, or replace log4j.properties with log4j.xml in your web-app.

    I've never tried a custom LoggerFactory before, but it may be that because it is installed by the configurator you can use standard getLogger factory calls, e.g.

    //Logger logger = AppServerLogger.getLogger("some.log");
    Logger logger = Logger.getLogger("some.log");
    

提交回复
热议问题