Yoav
Yoav

Reputation: 645

Log4j on Linux server

I have Linux server on which I run tomcat with my axis2 webservice.

I use the following for Log4j: xml configuration file, which is located in the same directory as my webservice java file.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Appenders -->
    <appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
        <param name="file" value="~//..//tmp//CookTalesLog.log" />
                <param name="append" value="true" />
                <param name="encoding" value="UTF-8" />
                <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                        <!-- The file to roll to, this is a fairly intelligent parameter, if the file
                        ends in .gz, it gzips it, based on the date stamp it rolls at that time, 
                        default is yyyy-MM-dd, (rolls at midnight)
                        See: http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html -->
                        <param name="FileNamePattern" value="CookTalesLog.%d.log.gz" />
                </rollingPolicy>

                <layout class="org.apache.log4j.PatternLayout">
                        <!-- The log message pattern -->
                        <param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
                </layout>
    </appender>

    <root>
        <priority value="debug" />
        <appender-ref ref="roll" />
    </root>

</log4j:configuration>

In the java code: I tried to use each of the following lines

private static final Logger sLogObj = Logger.getLogger( ICDBWebService.class );

private static final Log sLogObj = LogFactory.getLog(ICDBWebService.class);

also used:

static
{
    DOMConfigurator.configure( "log4j.xml" );
}

For logging:

    sLogObj.debug( "Login: email=" + email + " pwd= " + password );

Log file is not created....

Any ideas what am I doing wrong?

Upvotes: 0

Views: 9013

Answers (3)

Anshu Kunal
Anshu Kunal

Reputation: 196

Use the following to load xml file in your java code:

 DOMConfigurator.configureAndWatch("log4jConfigFile.xml");
 private static final Log log = LogFactory.getLog(ICDBWebService.class);

Upvotes: 0

andih
andih

Reputation: 5603

The double '//' may be a problem.

You can enable the internal debug output of Log4J by passing -Dlog4j.debug=true to the JVM or if running on Tomcatexport TOMCAT_OPTS="-Dlog4j.debug=true to see what's happening inside Log4J.

Upvotes: 2

chooban
chooban

Reputation: 9256

Have you tried a simpler file path? Instead of the tilde and double-slashes you have in there at the moment, try just using something like /tmp/CookTalesLog.log and see if that helps. It could be simply that the file name doesn't expand properly so it can't be created. Is there anything in the Tomcat logs to suggest a problem?

Upvotes: 0

Related Questions