tomcat hosting log4j log

  Since the project Tomcat log more and more, look for logs is very inconvenient, so after some investigation may be hosting Tomcat log way through log4j, implement Tomcat log slice. Here only shows how log4j is hosting Tomcat log, as to how segmentation do not explain, you can configure the log4j.properties file to achieve.

  1. Preparing Files:
    1. tomcat-juli.jar, tomcat-juli- adapters.jar. Download (tomcat's official website): https://tomcat.apache.org/download-70.cgi , or: http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.63/bin/extras / (corresponding to the version number can be changed)
    2. log4j-1.2.16.jar (log4j used in the project dependencies), log4j.properties (write your own log4j configuration file)

    Download interface, as shown below:

     

  1. The tomcat-juli.jar into the Tomcat / bin directory, replacing the original file
  2. The tomcat-juli-adapters.jar, log4j-1.2.16.jar, log4j.properties put under Tomcat / lib directory
  3. Logging.properties delete or rename the file in the Tomcat / conf directory
  4. Modify Tomcat / conf / context.xml file, <Context> to <Context swallowOutput = "true">. (Increase swallowOutput = "true" attribute configuration, the only way to complete the tomcat's stdout to take over)
  5. Restart Tomcat, hosting configuration is complete.

  Attach a simple example log4j.properties configuration file: the following code, I tested in time, if the Console open, it will result in duplicate output of log information, so here commented out

log4j.rootLogger=info,ROLLING_FILE

#Console
#log4j.appender.Console=org.apache.log4j.ConsoleAppender
#log4j.appender.Threshold=WARN
#log4j.appender.CONSOLE.Target=System.out
#log4j.appender.Console.layout=org.apache.log4j.PatternLayout
#log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
 
#file
log4j.appender.ROLLING_FILE = org.apache.log4j.DailyRollingFileAppender
log4j.appender.ROLLING_FILE.File = ${catalina.home}/logs/smartbear.log
log4j.appender.ROLLING_FILE.DatePattern = '.'yyyy-MM-dd
log4j.appender.ROLLING_FILE.Append = true
log4j.appender.ROLLING_FILE.Threshold = INFO
log4j.appender.ROLLING_FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

 

Guess you like

Origin www.cnblogs.com/smartbear/p/11456696.html