Hello,

I would like to gather all the logs from Jetty and the webapps it contains
in the same place, using Logback, and I've followed the instructions here:
http://www.eclipse.org/jetty/documentation/current/example-logging-logback-centralized.html

This seems to work, but I would also like to be able to tell from which
webapp the logs come from (in particular if the same or two similar webapps
are deployed under distinct context paths).
I'm using Logback and SLF4J throughout the applications (and loggers
obtained with "static Logger LOGGER = LoggerFactory.get(TheClassName.class);"),
and Jetty 9.3.7.

Logging the context path would be great, and
org.eclipse.jetty.webapp.logging.ContextLogHandler does some of it via MDC
but:
- it only seems to work within the scope of a request (whereas the webapps
also run code independently of any requests),
- for some reason, although %X{servername} or %X{target} work fine,
%X{contextPath} always appears empty. I'm using this encoder pattern for
testing:
    <pattern>%d{HH:mm:ss.SSS} - %contextName - %X{servername}
%X{contextPath} %X{target} - [%thread] %-5level %logger{36} -
%msg%n</pattern>


I've also tried to use Logback's JNDI selector, as described here:
http://logback.qos.ch/manual/loggingSeparation.html
I've set "logback/context-name" as follows (and the plus and jndi modules
were already enabled and working):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "
http://www.eclipse.org/jetty/configure_9_0.dtd";>
    <Configure id="wac_test1"
class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/test1</Set>
        <Set name="resourceBase"><SystemProperty name="jetty.home"
default="."/>/test1</Set>
        <New class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg>
                <Ref refid="wac_test1" />
            </Arg>
            <Arg>jdbc/myDataSource</Arg>
            <Arg>
                <!-- Removed from brevity... -->
            </Arg>
        </New>

        <New class="org.eclipse.jetty.plus.jndi.EnvEntry">
            <Arg>
                <Ref refid="wac_test1" />
            </Arg>
            <Arg>logback/context-name</Arg>
            <Arg type="java.lang.String">test1</Arg>
            <Arg type="boolean">true</Arg>
        </New>
    </Configure>


If I run Jetty with -Dlogback.ContextSelector=JNDI, I get this error:

    java.lang.NoClassDefFoundError: Could not initialize class
org.eclipse.jetty.jndi.NamingUtil
            at
org.eclipse.jetty.plus.jndi.NamingEntry.<clinit>(NamingEntry.java:44)
            at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at org.eclipse.jetty.util.TypeUtil.construct(TypeUtil.java:580)
            at
org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:787)
            at
org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:423)
            at
org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:358)
            at
org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:259)
            at
org.eclipse.jetty.deploy.providers.WebAppProvider.createContextHandler(WebAppProvider.java:305)
            at org.eclipse.jetty.deploy.App.getContextHandler(App.java:105)


If I run it with -Dlogback.ContextSelector=JNDI and also --exec, the
exception above no longer appears, but %{contextName} is always "default",
whether the logs come from the container or from the webapp.


Is there any way to combine Jetty and Logback so as to centralize the logs
but keep an extra indicator of the context path (or something related,
except when the logs come from the container), preferably keeping all the
Logback configuration in one place (e.g. resources/logback.xml)?


Best wishes,

Bruno.
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to