Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you use Spring you can:</p> <p>1) create a log4j configuration file, e.g. "/WEB-INF/classes/log4j-myapp.properties" DO NOT name it "log4j.properties"</p> <p>Example:</p> <pre><code>log4j.rootLogger=ERROR, stdout, rollingFile log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - &lt;%m&gt;%n log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender log4j.appender.rollingFile.File=${myWebapp-instance-root}/WEB-INF/logs/application.log log4j.appender.rollingFile.MaxFileSize=512KB log4j.appender.rollingFile.MaxBackupIndex=10 log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout log4j.appender.rollingFile.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.rollingFile.Encoding=UTF-8 </code></pre> <p>We'll define "myWebapp-instance-root" later on point (3)</p> <p>2) Specify config location in web.xml:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/classes/log4j-myapp.properties&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>3) Specify a <strong>unique</strong> variable name for your webapp's root, e.g. "myWebapp-instance-root"</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;webAppRootKey&lt;/param-name&gt; &lt;param-value&gt;myWebapp-instance-root&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>4) Add a Log4jConfigListener:</p> <pre><code>&lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>If you choose a different name, remember to change it in log4j-myapp.properties, too.</p> <p>See my article (Italian only... but it should be understandable): <a href="http://www.megadix.it/content/configurare-path-relativi-log4j-utilizzando-spring" rel="noreferrer">http://www.megadix.it/content/configurare-path-relativi-log4j-utilizzando-spring</a></p> <p><strong>UPDATE (2009/08/01)</strong> I've translated my article to English: <a href="http://www.megadix.it/node/136" rel="noreferrer">http://www.megadix.it/node/136</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload