Programmatically configure Jetty's logger

蹲街弑〆低调 提交于 2019-12-07 07:16:33

问题


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

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