本文介绍了Jetty中的log4j设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用log4j记录消息的Java Web应用程序.该webapp是我编写的jar文件的包装.当我通过Eclipse的内置Jetty运行我的Web应用程序时,我的JAR日志(LOG.info(...)消息)就可以很好地打印出来了.现在,我已经下载了Jetty的独立实例,并从那里运行了我的Web应用程序.使用Jetty附带的默认log4j设置,我无法从我的JAR中看到任何日志.我只看到Jetty日志和Webapp的日志.

I have a java webapp that uses log4j to log messages. This webapp is a wrapper around a jar file that I have written. When I run my webapp through the built-in Jetty from Eclipse, my JAR's logs (LOG.info(...) messages) are printed out just fine. Now, I have downloaded a standalone instance of Jetty and have run my web app from there. With the default log4j settings packaged with Jetty, I am not able to see ANY logs from my JAR. I only see the Jetty logs and the webapp's logs.

我已经在resources文件夹下找到了log4j.properties文件,但是不确定是否需要更改它才能显示应用程序的日志.我以为Jetty可以使用基本的log4j日志功能开箱即用.

I have found the log4j.properties file under the resources folder, but am not sure what I need to change in it to get my app's logs to show. I had thought that Jetty worked out of the box with basic log4j logging.

推荐答案

Jetty不使用log4j.

Jetty doesn't use log4j.

您需要配置${jetty.base}(重要说明:请勿编辑/修改/删除${jetty.home}中的任何内容),以便先使用slf4j,然后使用log4j.

You'll need to configure your ${jetty.base} (Important Note: do not edit/modify/delete any content in ${jetty.home}) to use slf4j first, log4j second.

$ cd /path/to/myjettybase
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=resources,ext

下一步,去下载slf4j-api.jarslf4j-log4j##.jar(其中##是要使用的log4j的支持版本)和log4j.jar并将它们放在新的${jetty.base}/lib/ext目录中.

Next, go download slf4j-api.jar, slf4j-log4j##.jar (where ## is the support version of log4j you want to use), and log4j.jar and put them in the new ${jetty.base}/lib/ext directory.

最后,将log4j.xml放在${jetty.base}/resources/目录中.

就是这样,您已经设置了Jetty Distribution以供log4j使用.

That's it, you've setup Jetty Distribution for log4j use.

这篇关于Jetty中的log4j设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 08:57