2019-07-03 20:51
@JFinal 谢谢波总 ,解决了,参考springboot里面对undertow access log 的实现完成,不过单独靠
UndertowServer.create(JFinalConfig.class)
.onStart( builder -> {
builder.setServerOption(UndertowOptions.参数名, 参数值);
})
.start();
这样好像无法解决,
AccessLogHandler日志处理类 的构造方法为
public AccessLogHandler(HttpHandler next, AccessLogReceiver accessLogReceiver, String formatString, ClassLoader classLoader) {
this(next, accessLogReceiver, formatString, classLoader, Predicates.truePredicate());
}
lambda表达式 内无法获取HttpHandler 对象所以无法构造日志对象,最后还是覆盖了写一个类继承UndertowServer覆盖了configHttp()方法完成了,代码如下
Xnio xnio = Xnio.getInstance(Undertow.class.getClassLoader());
XnioWorker worker = null;
try {
worker = xnio.createWorker(OptionMap.builder().set(Options.THREAD_DAEMON, true).getMap());
} catch (IOException e) {
e.printStackTrace();
}
DefaultAccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver(worker,
new File(System.getProperty("logPath")), "undertow_access_log.", "log", true);
builder.addHttpListener(config.getPort(), config.getHost())
.setHandler(pathHandler).setHandler(new AccessLogHandler(httpHandler, accessLogReceiver,
"common", Undertow.class.getClassLoader()));
不知道波总有没有更好的建议,希望在下一个版本添加对访问日志配置的支持,因为这个功能还是挺实用的