简体   繁体   English

如何通过Maven项目的LOG_LEVEL过滤码头日志?

[英]How to filter jetty logs by LOG_LEVEL of maven project?

I have problems with logging in jetty. 我在登录码头时遇到问题。 I write logs in file. 我在文件中写入日志。 In resulting log's file a logging level for application is info, but I set set it like WARN. 在生成的日志文件中,应用程序的日志记录级别为info,但我将其设置为WARN。 I have idea that jetty write logs from application without filtering, is it so? 我有个想法,码头不使用过滤器从应用程序写入日志,是吗?

  1. I use maven and I've packaged my application with command 我使用Maven,并用命令打包了我的应用程序

     sudo mvn package 
  2. set up logging for jetty: 设置码头的日志记录:

     {jetty.base}/modules$ sudo curl -O https://raw.githubusercontent.com/jetty-project/logging-modules/master/log4j-1.2/logging.mod {jetty.base}$ sudo java -jar /opt/jetty/start.jar --add-to-start=logging 
  3. File {jetty.base}/resources/jetty-logging.properties 文件{jetty.base} /resources/jetty-logging.properties

     org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog org.apache.log4j.LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN); org.eclipse.jetty.LEVEL=WARN 
  4. File {jetty.base}/resources/log4j.properties 文件{jetty.base} /resources/log4j.properties

     log4j.rootLogger=WARN, file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 
  5. File {jetty.base}/etc/jetty-logging.xml 文件{jetty.base} /etc/jetty-logging.xml

     <New id="ServerLog" class="java.io.PrintStream"> <Arg> <New class="org.eclipse.jetty.util.RolloverFileOutputStream"> <Arg><Property name="jetty.logs" default="/mnt/logs"/>/yyyy_mm_dd.stderrout.log</Arg> <Arg type="boolean">false</Arg> <Arg type="int">90</Arg> <Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg> <Get id="ServerLogName" name="datedFilename"/> </New> </Arg> </New> <Get name="rootLogger"> <Call name="info"><Arg>Redirecting stderr/stdout to file <Ref refid="ServerLogName"/></Arg></Call> </Get> <Call class="java.lang.System" name="setErr"><Arg><Ref refid="ServerLog"/></Arg></Call> <Call class="java.lang.System" name="setOut"><Arg><Ref refid="ServerLog"/></Arg></Call> 

  6. In logs file I see logging with level Info and debug 在日志文件中,我看到使用信息级别和调试级别进行日志记录

     07:13:10.072 [main] INFO 07:14:04.216 [java-sdk-http-connection-reaper] DEBUG oahicPoolingClientConnectionManager ... 

Ignore the etc/jetty-logging.xml , your setup isn't using it (you downloaded a custom modules/logging.mod that does not reference it) 忽略etc/jetty-logging.xml ,您的设置未使用它(您下载了未引用它的自定义modules/logging.mod

You can see what your configuration is using by running start.jar --list-config 您可以通过运行start.jar --list-config查看使用start.jar --list-config

That XML only exists to support the built-in StdErrLog implementation that only writes to System.err (aka STDERR). 该XML仅用于支持仅写入System.err (也称为STDERR)的内置StdErrLog实现。 The etc/jetty-logging.xml just takes STDERR and STDOUT and writes it to disk. etc/jetty-logging.xml只接受STDERR和STDOUT并将其写入磁盘。

Since you are using log4j , that entire redirect step is not needed (and would conflict with normal log4j console appender behavior if it were used). 由于您使用的是log4j ,因此不需要整个重定向步骤(如果使用了log4j控制台附加程序,则该操作会与常规行为冲突)。

Your ${jetty.base}/resources/jetty-logging.properties should only be: 您的${jetty.base}/resources/jetty-logging.properties应该仅是:

org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog

It should contain no other lines. 它不应包含其他行。

The file ${jetty.base}/resources/log4j.properties is where you configure your initial named logger levels, and all of the initial appenders you want to use. 文件${jetty.base}/resources/log4j.properties是配置初始命名记录器级别以及要使用的所有初始附加器的位置。

You currently have the initial level for set to WARN. 当前,您已将初始级别设置为WARN。

When your server starts up, any piece of code you have can (at runtime) decide to change the level of a specific named logger, and even add/remove appenders at runtime (this is more common then you might expect) 当服务器启动时,您拥有的任何代码段都可以(在运行时)决定更改特定命名记录器的级别,甚至可以在运行时添加/删除附加程序(这比您预期的更常见)

Since you don't have a Threshold declared for your appender, it will take all levels seen and append them. 由于您没有为附加程序声明Threshold ,因此它将显示所有级别并将其附加。

If you don't want to see that DEBUG in your appender, just add the following line to your ${jetty.base}/resources/log4j.properties 如果您不想在附加程序中看到该调试,只需${jetty.base}/resources/log4j.properties添加到${jetty.base}/resources/log4j.properties

log4j.appender.file.Threshold=WARN

But you might still want to know what is setting that named logger level outside of the properties file. 但是您可能仍然想知道是什么在属性文件之外设置了命名记录器级别。 (check your code) (检查您的代码)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM