如何配置码头以将日志放入外部文件 [英] How to configure jetty to put logs into an external file

查看:321
本文介绍了如何配置码头以将日志放入外部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置码头将其日志放入外部文件?

How to configure jetty to put its logs into an external file?

手册说,我必须将slf4j放到lib目录中.

Manual says that I have to put slf4j into the lib directory.

我所做的是:

  • 下载slf4j并将slf4j-log4j12-1.7.3.jar放入$ JETTY_HOME $/lib中.
  • 下载log4j并将log4j-1.2.17.jar放入$ JETTY_HOME $/lib
  • 创建一个log4j配置文件.可以从下面获得:
<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"

      尽管我做了上面描述的所有事情,但是在目标位置看不到任何日志.所有日志条目仍可从控制台获得

      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

      推荐答案

      更新说明(2016年6月)

      对于Jetty 9+,您将使用分开的${jetty.home}${jetty.base}目录.

      注意:请勿编辑/修改/删除/添加/删除${jetty.home}中的任何内容.从现在开始,所有配置都将驻留在${jetty.base}中.

      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.

      作为命令行的指令:

      $ 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
      

      注意:请勿启用logging模块,因为这仅适用于Jetty的StdErrLog实现.该logging模块将捕获任何System.errSystem.out并将其重定向到滚动日志文件.此捕获和重定向将与您的log4j ConsoleAppender直接冲突!

      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!

      原始说明-仅对Jetty 8(现EOL)及更早版本有效

      请按照以下步骤操作:

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

      Follow these steps:

      1. $JETTY_HOME/lib中创建一个日志目录:$JETTY_HOME/lib/logging(这只是最佳做法)
      2. log4jslf4j-log4jslf4j-api放入该目录中: 例如:log4j-1.2.16.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar
      3. 通过在$JETTY_HOME/start.ini OPTIONS行中添加"logging",确保在码头的类路径中具有该新目录: 例如:OPTIONS=Server,websocket,resources,ext,jsp,jdbc,logging
      4. 将您的log4j.properties放置在$JETTY_HOME/resources目录中
      5. 开始码头
      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

      如果正确设置了log4j.properties,则此设置将为您工作.我会小心地在文档中提供此类分步指南.

      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.

      这篇关于如何配置码头以将日志放入外部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆