How to configure jetty to put logs into an external file

后端 未结 1 1770
渐次进展
渐次进展 2021-02-06 07:38

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:

  • downloa
相关标签:
1条回答
  • 2021-02-06 08:02

    Updated Instructions (June 2016)

    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's StdErrLog implementation. That logging module will capture any System.err and System.out and redirect it to a rolling log file. This capture and redirect will be in direct conflict with your log4j ConsoleAppender!

    Original Instructions - Only valid on Jetty 8 (now EOL) and older

    Follow these steps:

    1. create a logging directory in $JETTY_HOME/lib: $JETTY_HOME/lib/logging (this is just best practice)
    2. put 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
    3. make sure to have that new directory in jetty's classpath by adding "logging" in your $JETTY_HOME/start.ini OPTIONS line: e.g.: OPTIONS=Server,websocket,resources,ext,jsp,jdbc,logging
    4. place your log4j.properties in $JETTY_HOME/resources directory
    5. start jetty

    If 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.

    0 讨论(0)
提交回复
热议问题