erickrar
By:
erickrar

log4j.xml with system environment and Tomcat 7

August 7, 2014 5.4k views

Hello,
I have some problem trying use log4j with System environment.
This is my log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC  "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="main" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss} %5p [%-20c{1}] %m%n" />
        </layout>
    </appender>

    <appender name="file" class="org.apache.log4j.RollingFileAppender">
        <param name="append" value="false" />
        <param name="maxFileSize" value="10MB" />
        <param name="maxBackupIndex" value="10" />
        <param name="file" value="${CATALINA_HOME}/logs/info.log" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <category name="org.jboss.logging">
        <priority value="WARN" />
        <appender-ref ref="main" />
    </category>

    <category name="org.jboss.weld">
        <priority value="INFO" />
        <appender-ref ref="main" />
    </category>

    <logger name="controller">
        <level value="INFO" />
        <appender-ref ref="main" />
        <appender-ref ref="file" />
    </logger >
</log4j:configuration>

I can see the logs on catalina.out, but is not creating the info.log.

Works fine on my computer, lol.
Ty,

1 Answer

Does ${CATALINA_HOME}/logs/info.log exist? You might need to create the file and allow Tomcat to write to it.

If catalina.out works fine, you can transfer its permissions to info.log:

sudo chmod --reference /path/to/catalina.out /path/to/info.log
sudo chown --reference /path/to/catalina.out /path/to/info.log
Have another answer? Share your knowledge.