嵌入式Undertow日志输出

Embedded Undertow log output

我想配置我的嵌入式 Undertow 以将服务器日志保存到文件中

public class Server {
     UndertowJaxrsServer server = new UndertowJaxrsServer();

     ResteasyDeployment deployment = new ResteasyDeploymentImpl();
     deployment.setApplicationClass(ExampleApplication.class.getName());
     deployment.setInjectorFactoryClass("org.jboss.resteasy.cdi.CdiInjectorFactory");
     DeploymentInfo deploymentInfo = server.undertowDeployment(deployment, "/");
     deploymentInfo.setClassLoader(Server.class.getClassLoader());
     deploymentInfo.setDeploymentName("service");
     deploymentInfo.setContextPath("/service");
     deploymentInfo.addListener(Servlets.listener(Listener.class));
     server.deploy(deploymentInfo);

     Builder builder = Undertow.builder()
            .addHttpListener("8080", "localhost")    

}

服务器日志显示在控制台中,但我想将所有服务器日志保存到一个文件中(类似于 JBoss 服务器日志,每天将它们保存到日志文件中)。我该如何配置?

鉴于您使用 log4j 作为日志管理器,您需要修改配置文件。对于 log4j.properties 它看起来像:

log4j.rootLogger=DEBUG, file

# My Application Log
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log4j.log
log4j.appender.file.logfile.Threshold=ALL
log4j.appender.file.MaxBackupIndex=100
log4j.appender.file.MaxFileSize=1Gb
log4j.appender.file.encoding=UTF8
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%p %t %c - %m%n