问题
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.
回答1:
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.
回答2:
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);
来源:https://stackoverflow.com/questions/1523595/programmatically-configure-jettys-logger