Log4j is often used for log output during web development. The log level is frequently adjusted during software test run.
If you modify log4j. xml once and restart the web application, it is very troublesome.
The following program can implement dynamic configuration of log4j. xml.
(After modifying log4j. XML, run the JSP program under the supervisor.
This program does not provide the function of visually configuring log4j. xml.
)
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<%
Response. setheader ("Pragma", "No-Cache ");
Response. setheader ("cache-control", "No-Cache ");
Response. setdateheader ("expires", 0 );
%>
<HTML>
<Head>
<Title> reconfigure log4j </title>
<Link href = "$ {pagecontext. Request. contextpath}/CSS/styleqxgl.css" rel = "stylesheet" type = "text/CSS">
</Head>
<Body>
<%
Try {
String location = config. getservletcontext (). getinitparameter ("log4jconfiglocation ");
Out. println ("location =" + location + "<br> ");
If (! Org. springframework. util. resourceutils. isurl (location )){
// Resolve system property placeholders before resolving real path.
Location = org. springframework. util. systempropertyutils. resolveplaceholders (location );
Location = org. springframework. Web. util. webutils. getrealpath (config. getservletcontext (), location );
}
Java.net. url = org. springframework. util. resourceutils. geturl (location );
Org. Apache. log4j. xml. domconfigurator. Configure (URL );
Out. println ("log4j reconfiguration successful! <Br> ");
Out. println ("time:" + COM. Work. util. dateutil. getcurrentdatetime ());
} Catch (exception e ){
Out. println ("log4j configuration failed! "+ E. getmessage ());
}
%>
<HR>
</Body>
</Html>