如何配置码头以将日志放入外部文件 [英] How to configure jetty to put logs into an external file
问题描述
如何配置码头将其日志放入外部文件?
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.err
和System.out
并将其重定向到滚动日志文件.此捕获和重定向将与您的log4jConsoleAppender
直接冲突!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
!原始说明-仅对Jetty 8(现EOL)及更早版本有效
请按照以下步骤操作:
Original Instructions - Only valid on Jetty 8 (now EOL) and older
Follow these steps:
- 在
$JETTY_HOME/lib
中创建一个日志目录:$JETTY_HOME/lib/logging
(这只是最佳做法) - 将
log4j
,slf4j-log4j
和slf4j-api
放入该目录中: 例如:log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
- 通过在
$JETTY_HOME/start.ini
OPTIONS
行中添加"logging
",确保在码头的类路径中具有该新目录: 例如:OPTIONS=Server,websocket,resources,ext,jsp,jdbc,logging
- 将您的
log4j.properties
放置在$JETTY_HOME/resources
目录中 - 开始码头
- create a logging directory in
$JETTY_HOME/lib
:$JETTY_HOME/lib/logging
(this is just best practice) - put
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
- 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
- place your
log4j.properties
in$JETTY_HOME/resources
directory - 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屋!
- 在