log4j settings in Jetty

不想你离开。 提交于 2020-01-25 20:16:31

问题


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.

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.


回答1:


Jetty doesn't use 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

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.

Finally, put your log4j.xml in your ${jetty.base}/resources/ directory.

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



来源:https://stackoverflow.com/questions/37643195/log4j-settings-in-jetty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!