0

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.

user972276
  • 2,973
  • 9
  • 33
  • 46

1 Answers1

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.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Actually, I forgot I am using logback instead of log4j, but anyways... I added the logback jars and I am getting log messages saying multiple slf4j bindings have been found. – user972276 Jun 06 '16 at 19:14
  • Forgot to elaborate... I am seeing some debug messages from my app, but the explicit LOG.info(...) messages are still not getting printed – user972276 Jun 06 '16 at 19:48
  • http://stackoverflow.com/questions/14024756/slf4j-class-path-contains-multiple-slf4j-bindings – Joakim Erdfelt Jun 06 '16 at 19:51
  • You can't have app generated logging pass through the WebApp isolation layers. You either have Server logging, or App logging, each configured separately, with different Appenders (and file locations!) – Joakim Erdfelt Jun 06 '16 at 19:53
  • I updated my OP. I just realized that the issue is not with my webapp, but a jar that is packaged with the webapp. That jar's logging is not printed. – user972276 Jun 07 '16 at 12:51