log4j: how to enable it ?

  • giluka

    giluka - 2013-06-10

    Hi all,
    how can i enable log4j on OX ?
    In /properties/log4j.properties i've a configuration properties file that i don't understand how to initialize ...


  • Granjero Moe

    Granjero Moe - 2013-06-12

    Hi giluka.

    I added log4j to my OX project in this way:

    Add these lines to your web.xml file:

    <!-- Servlet para inicializar la configuración de Log4J -->

    Add the servlet Log4jInit

    package project.web.servlet;
    import javax.servlet.http.HttpServlet;
    import org.apache.log4j.xml.DOMConfigurator;
    public class Log4jInit extends HttpServlet {
        public void init() {
            String prefix = getServletContext().getRealPath("/");
            String file = getInitParameter("log4j-init-file");
            // if the log4j-init-file is not set, then no point in trying
            if (file != null) {
                DOMConfigurator.configure(prefix + file);

    And add the config log4j.xml file. This is an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "dtds/log4j.dtd" >
        <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
            <param name="Target" value="System.out" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                    value="[%d{ISO8601}] %-5p [%c] %m %n" />
                <param name="ConversionPattern" value="%-5p [%c] %m %n" />
        <appender name="STDERR" class="org.apache.log4j.ConsoleAppender">
            <param name="Target" value="System.err" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                    value="[%d{ISO8601}] %-5p [%c] %m %n" />
            <filter class="org.apache.log4j.varia.LevelRangeFilter">
                <param name="LevelMin" value="ERROR" />
                <param name="LevelMax" value="FATAL" />
        <appender name="SW_ROLLING_FILE"
            <param name="File" value="${catalina.home}/logs/project_log4j.log" />
            <param name="Append" value="true" />
            <param name="MaxFileSize" value="500KB" />
            <param name="MaxBackupIndex" value="5" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                    value="[%d{ISO8601}] %-5p %m%n" />
            <level value="ERROR" />
            <appender-ref ref="STDERR" />
            <appender-ref ref="SW_ROLLING_FILE" />
  • giluka

    giluka - 2013-06-13

    thanks !!


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks