[英]How do I configure embedded jetty server to log all requests?
I want to log all soap requests to my server. 我想将所有soap请求记录到我的服务器。 The server instance is an embedded jetty server.
服务器实例是嵌入式jetty服务器。
Is there a way to setup a handler to do this. 有没有办法设置处理程序来执行此操作。 I have access to the web.xml file
我可以访问web.xml文件
You'll want the following on your embedded jetty startup... 您需要在嵌入式Jetty启动中使用以下内容...
(This is assuming Jetty 9) (这是假设Jetty 9)
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
// your context specific handlers are added to "contexts" here
server.setHandler(handlers);
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename("/path/to/my/logs/yyyy_mm_dd.request.log");
requestLog.setFilenameDateFormat("yyyy_MM_dd");
requestLog.setRetainDays(90);
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone("GMT");
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
jetty maven: 码头maven:
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<version>9.3.8.v20160314</version>
<type>pom</type>
</dependency>
Code: 码:
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename("/path/to/my/logs/yyyy_mm_dd.request.log");
requestLog.setFilenameDateFormat("yyyy_MM_dd");
requestLog.setRetainDays(90);
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone("GMT"); // or GMT+2 and so on.
server.setRequestLog(requestLog); // here will set global request log
NCSARequestLog is sync log, if you want to use log4j, do it like that: NCSARequestLog是同步日志,如果你想使用log4j,那就这样做:
public class AccessLogHandler extends AbstractNCSARequestLog {
private Log logger = LogFactory.getLog(AccessLogHandler.class);
@Override
protected boolean isEnabled() {
return true;
}
@Override
public void write(String requestEntry) throws IOException {
logger.info(requestEntry);
}
}
use AccessLogHandler
to replace the NCSARequestLog
and config your log4j.properties
. 使用
AccessLogHandler
替换NCSARequestLog
并配置log4j.properties
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.