Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not sure what you really wanna do....</p> <p>if your log4j.xml is in the classpath, when you start your app-server, it should be loaded automatically.</p> <p>Check the console when you start your server and you should see your log4j info.</p> <p>You can also put debug=true:</p> <pre><code>&lt;log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/"&gt; </code></pre> <p>in your xml. you will be able to see a lot of info about your config.</p> <p>Now if you want to access the appenders you configured in the log4j.xml, all you have to do is:</p> <pre><code>Logger mylogger = Logger.getLogger("MyAppenderName"); </code></pre> <p>Ok, i think you wanna load a custom log4j config file! In a web app context, you will need 2 things:</p> <p>create a contextListnerServlet; modify your web.xml</p> <p>ServletListner:</p> <pre><code>public class StartupListener implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent arg0) { // Cleanup code goes here } @Override public void contextInitialized(ServletContextEvent sce) { Logger logger = null; String log4jFile = sce.getServletContext().getInitParameter("log4jFileName"); DOMConfigurator.configure(sce.getServletContext().getRealPath(log4jFile)); logger = LogManager.getLogger(StartupListener.class.getName()); logger.debug("Loaded: " + log4jFile); } </code></pre> <p>web.xml:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;log4jFileName&lt;/param-name&gt; &lt;param-value&gt; WEB-INF/config/log4j-my.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt; com.yourpackage.StartupListener &lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>Hope it helps</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