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:
<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
For Jetty 9+, you'll be using a split ${jetty.home}
and ${jetty.base}
directory.
Note: do not edit/modify/delete/add/remove any content in
${jetty.home}
. All of your configuration will reside in${jetty.base}
from now on.
Instructions as command line:
$ mkdir /path/to/mybase
$ cd /path/to/mybase
# Prepare a basic jetty.base directory
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=http,deploy,resources,ext
INFO: ext initialised in ${jetty.base}/start.ini
INFO: resources initialised in ${jetty.base}/start.ini
INFO: server initialised (transitively) in ${jetty.base}/start.ini
INFO: http initialised in ${jetty.base}/start.ini
INFO: deploy initialised in ${jetty.base}/start.ini
MKDIR: ${jetty.base}/lib
MKDIR: ${jetty.base}/lib/ext
MKDIR: ${jetty.base}/resources
MKDIR: ${jetty.base}/webapps
INFO: Base directory was modified
# Download the required jar files
$ cd /path/to/mybase/lib/ext
$ curl -O http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar
$ curl -O http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar
$ curl -O http://central.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar
# Prepare the Jetty side logging to use slf4j
$ cd /path/to/mybase/resources
$ echo "org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog" > jetty-logging.properties
# Grab a copy of a log4j.xml to initialize things
$ cd /path/to/mybase/resources
$ curl -o log4j.xml https://gist.githubusercontent.com/joakime/13e31db59b83079be3fdc1a877de7060/raw/5c275a2a2f29445d6cdde7fcae3820da99e7234b/log4j.xml
# Start Jetty
$ cd /path/to/mybase
$ java -jar /path/to/jetty-dist/start.jar
Note: do not enable the
logging
module as that is strictly for Jetty'sStdErrLog
implementation. Thatlogging
module will capture anySystem.err
andSystem.out
and redirect it to a rolling log file. This capture and redirect will be in direct conflict with your log4jConsoleAppender
!
Follow these steps:
$JETTY_HOME/lib
: $JETTY_HOME/lib/logging
(this is just best practice)log4j
, slf4j-log4j
and slf4j-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With