Converting log4j.properties file for Tomcat to work with Log4j2

后端 未结 3 1123
庸人自扰
庸人自扰 2021-02-03 13:18

I\'m trying to configure Tomcat 8 to use Log4j2 for logging.

I\'ve found this reference for Logging in Tomcat using Log4j. It provides a sample log4j.properties file th

3条回答
  •  抹茶落季
    2021-02-03 13:37

    I followed the reference for Logging in Tomcat using Log4j and added tomcat-juli.jar to the bin dir and I also added tomcat-juli-adapters.jar to the lib dir. Afterwards i added the log4j-api-2.1.jar, log4j-core-2.1.jar and log4j-1.2-api-2.1.jar to the lib dir.

    After that I added log4j2.xml to the lib dir. I kept the configuration fairly simple using a time and size based rolling configuration that zips the archived logs:

    
    
    
        
            
                
                    %d{MMM d, yyyy HH:mm:ss}: %5p (%F:%L) - %m%n
                
                
                    
                    
                
                
            
        
        
            
            
                
            
            
                
            
        
    
    

    This way you'll get all logging in the catalina.log. I'm still working on getting the accessLog to do the same.
    EDIT: I found this site. this way you can direct access logging to the catalina.log. (I couldn't get it to log to it's own appender)

    I didn't worry about the logging for manager and host manager, since we don't have them in production environments, but they might just log to the catalina.log too. I haven't tested it.

    This was tested on tomcat-7.0.42, it should work in tomcat8 too.

提交回复
热议问题