Configure log in Tomcat

xiaoxiao2021-03-06  42

By Camry.Wu

Configure Commons-Logging and Log4j in Tomcat

Today, I have a log, and record actions.

I will copy Commons-Logging.jar and Log4j-xxx.jar to tomcat.home / common / lib /. In Tomcat.home / Common / Classes / Create a log4j.properties, so all output information can be control log4j.properties log4j.properties file:. # For JBoss: Avoid to setup Log4J outside $ JBOSS_HOME / server / default / deploy / log4j.xml # For all other servers:! Comment out the Log4J listener in web.xml to activate Log4J .log4j.rootLogger = INFO, stdout, logfilelog4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout = org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern =% d% p [ % c] - <% m>% nlog4j.appender.logfile = org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File = / home / camry / work / logs / xxxx.loglog4j.appender.logfile.MaxFileSize = 512KB # Keep three backup files.log4j.appender.logfile.MaxBackupIndex = 3 # Pattern to output: date priority [category] - messagelog4j.appender.logfile.layout = org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern =% D% p [% c] -% M% N is divided into several projects in your Tomcat, think of different The project log is written to different locations. You can create log4jinitservlet.class in the project to load log4j.properties of the project. You can put log4j.properties in Web-INF / Under, of course, willing to place other locations. The code is as follows: Web-inf / web.xml: log4j-init com.xxx.xxxx.log4jinitservlet Log4j /web-inf/log4j.properties 1 log4jinitservlet.java: ... package com.xxx.util; import org.apache.log4j.propertyConfigurator;

import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; / ** * to-do init log4j * / public class Log4jInitServlet extends HttpServlet {/ ** * initial. * / Public void init () {string prefix = getServletContext (). GetRealPath ("/"); // reads out the position String File = GetItParameter ("log4j"); PropertyConfigurator.configure (prefix file) } // end: init} // end: log4jinitservlet ... log4jinitservlet.java file can be used as a public util. Last update: March 19, 2005, Saturday, 23:22, 23:23, HTML conversion program: Tex2Page 2004- 09-11

转载请注明原文地址:https://www.9cbs.com/read-45237.html

New Post(0)