1
votes

I'm using a embedded jetty in my application and I have configured a war deployed folder as follow.

        // === jetty-deploy.xml ===

        DeploymentManager deployer = new DeploymentManager();
        deployer.setContexts(contexts);
        deployer.setContextAttribute(
                "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                ".*/servlet-api-[^/]*\\.jar$");

        WebAppProvider webapp_provider = new WebAppProvider();
        webapp_provider.setMonitoredDirName("jetty_base/webapps");
        //webapp_provider.setDefaultsDescriptor("jetty_base/webapps/webdefault.xml");
        webapp_provider.setScanInterval(1);
        webapp_provider.setExtractWars(true);
        webapp_provider.setConfigurationManager(new PropertiesConfigurationManager());

        deployer.addAppProvider(webapp_provider);
        server.addBean(deployer);


        org.eclipse.jetty.util.log.Log.setLog(new org.eclipse.jetty.util.log.StdErrLog());
        //Log.setLog(new Slf4jLog());

When I deploy my war file using standard jetty distribution (jetty-distribution-9.3.6.v20151106) I can get logs in my *.stderrout.log files.

But problem I face is I can't get logs when I use my above embedded jetty. I tried both StdErrLog and Slf4jLog for Log.setLog

In my war file there are logs with logback. Following line is extracted from log file of standard distribution

 INFO in ch.qos.logback.classic.LoggerContext[default]
1

1 Answers

2
votes

The creation of *.stderrlog.log files is an artifact of how jetty-distribution behaves, its not appropriate for , don't try to accomplish that end-goal.

As for configuring logging, that needs to happen early, as in VERY early, as early as you can possibly make it happen. If you can make it happen before you instantiate anything in Jetty that would be ideal.

Some options to try (only try 1 of the following, not a combination of them):

1) Let Jetty Logging Auto-Configure

By default, the existence of slf4j-api.jar in your classpath will cause jetty to auto-configure for slf4j (which in yourcase will use logback as its implementation)

Don't call Log.setLog() anywhere, let jetty do its thing.

2) Specify the Log.setLog() early

Try simply putting this static block in your main class.

static {
    org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
}

Don't call Log.setLog() anywhere else.

3) Add a jetty-logging.properties to your classpath

Create a jetty-logging.properties file somewhere where it will be in your classpath (the root of your jar file is a good place), add the following line:

org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog