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?
The double ‘//’ may be a problem.
You can enable the internal debug output of Log4J by passing
-Dlog4j.debug=trueto the JVM or if running on Tomcatexport TOMCAT_OPTS="-Dlog4j.debug=trueto see what’s happening inside Log4J.