This is the configuration of log4j in lift
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM
"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration threshold="trace" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CA" class="org.apache.log4j.FileAppender">
<param name="File" value="sample.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] %-8r [%t] %-5p %c %x - %m%n"/>
</layout>
</appender>
<root>
<level value="trace"/>
<appender-ref ref="CA"/>
</root>
</log4j:configuration>
This is the relevant part in Boot.scala
Logger.setup = Full(Log4j.withFile(getClass.getResource("/props/default.log4j.xml")))
I run the lift app on jetty 6.22. When i start jetty with “jetty service start”,
It creates the log file in the jetty tmp_dir folder /var/cache/jetty/tmp/sample.log
How can i configure it to create the log files in another location? for exmaple the jetty logs folder.
As you only use the filename ‘sample.log’ in your FileAppender declaration then Jetty stores the log file in its working directory.
The solution is to specify an absolute path, or potentially using a variable. For instance:
Would store sample.log in java.io.tmpdir which is OS dependent.
The value inside the curly braces is a system property. You can specify anything as a system property on the command line and then access it in your Log4J file. For example:
And then:
If the Jetty logging directory is a system property then you should be able to access it.