Search code examples
jbossundertow

Embedded Undertow log output


I want to configure my embedded Undertow to save the server logs into a file

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")    

}

The server logs are shown in the console but I want to save all the server logs to a file (similar to JBoss server log where they are saved to log files on daily basis). How can I configure that?


Solution

  • Given you're using log4j as the log manager you'd need to modify your configuration file. For a log4j.properties it would look something like:

    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