Steve Kuo
Steve Kuo

Reputation: 63094

Programmatically configure Jetty's logger

How do I programmatically configure Jetty's logger? I'm using Jetty in a standalone application and want to change the log level of some of Jetty's internally generated warnings. Ideally I could do this programmatically (ie, in code) without having to specify an XML file.

I'm using Jetty 6.1.20.

Upvotes: 4

Views: 8480

Answers (2)

Neil Ellis
Neil Ellis

Reputation: 111

If you need to get hold of the request logs only the solution is over at http://www.eclipse.org/jetty/documentation/current/configuring-jetty-request-logs.html

NCSARequestLog requestLog = new NCSARequestLog("/var/logs/jetty/jetty-yyyy_mm_dd.request.log");
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogTimeZone("GMT");

server.setRequestLog(requestLog);

Upvotes: 1

Vinko Vrsalovic
Vinko Vrsalovic

Reputation: 340321

Jetty uses slf4j, so you can use any logging framework or slf4j implementation you want .

Jetty comes with the Simple slf4j implementation, which logs INFO levels or above. So, you either change the bundled slf4j jars to an implementation with the log levels you want, or use a bridge to another framework with the levels you want, or provide a custom log class you can set via, for example,

System.setProperty("org.mortbay.log.class", "com.example.JettyLog");

More information here.

Upvotes: 3

Related Questions