How to configure jetty to put its logs into an external file?
Manual says that I have to put slf4j into the lib directory.
What I did was:
- download slf4j and put slf4j-log4j12-1.7.3.jar into $JETTY_HOME$/lib .
- download log4j and put log4j-1.2.17.jar into $JETTY_HOME$/lib
- create a log4j configuration file. it's available from below:
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG" />
<param name="File" value="c:/app/jetty/logs/server.log" />
<layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p [%c{1}] %m %n" />
</layout>
</appender>
<root>
<priority value="debug" />
<appender-ref ref="fileAppender" />
</root>
commented line
"#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog"
in$JETTY_HOME$/resources/jetty-logging.properties
Although I did everything what's described above, I am not able to see any logs in the target destinations. All log entries are still available from the console
Updated Instructions (June 2016)
For Jetty 9+, you'll be using a split
${jetty.home}
and${jetty.base}
directory.Instructions as command line:
Original Instructions - Only valid on Jetty 8 (now EOL) and older
Follow these steps:
$JETTY_HOME/lib
:$JETTY_HOME/lib/logging
(this is just best practice)log4j
,slf4j-log4j
andslf4j-api
in that directory: e.g.:log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
logging
" in your$JETTY_HOME/start.ini
OPTIONS
line: e.g.:OPTIONS=Server,websocket,resources,ext,jsp,jdbc,logging
log4j.properties
in$JETTY_HOME/resources
directoryIf your log4j.properties is properly setup this should work for you. I'll take care to have such a step by step guide in the documentation.