Log4j's formulation and test procedures

zhaozj2021-02-16  91

1. Write an initialized servlet:

Package net.welovetennis.util.log;

Import javax.servlet. *; import javax.servlet.http. *; import org.apache.log4j. *;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2004 *

Company: * @ Author not attributable * @version 1.0 * /

Public class log4jinit extends httpservlet {

// Initialize global variables public void init () throws ServletException {String prefix = getServletContext () getRealPath ( "/");. String file = getInitParameter ( "log4j"); // if the log4j-init-file is not set, Then no point in trying system.out.println ("................ log4j start"); if (file! = null) {PropertyConfigurator.configure (prefix file); }}} // process the http get request public void doget (httpservletRequest request, httpservletResponse response) {

} // clean up resources public void design () {}}

2. Modify the web. XML:

Log4jinit net.welovetennis.util.log.log4jinit log4j Web-inf / log4j.properties 1

3. Depending on Web-INF Dressing file log4j.properties, and specify the output path:

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

New Post(0)