[logback-user] Logback with Tomcat and multiple web applications

Ceki Gulcu ceki at qos.ch
Wed Feb 11 18:31:35 CET 2009

If I understand correctly, you would like to have the syslog output somehow 
include the current application name. Is that all?

More below.

Ryan Cornia wrote:
> I've been struggling with this in Log4J, and am wondering if it's possible
> in Logback.
> If I have tomcat, with several web applications, can I have one instance of
> the logback jars in Tomcat/lib, and one configuration file, but distinguish
> between applications via variable substitution and the pattern?
> We are logging to SYSLOG, so I would like the pattern to include the
> application name. 
> I looked through the manual, and see you can use variable substitution for
> specifying different files, but does substitution work in the pattern field?

Substitution variables work within the pattern field. However, I don't think 
that's what you want. You probably want to specify a conversion word whose value 
dynamically changes to the name of your application. Assuming you set the MDC 
key "applicationName" to the name of the application, then the following config 
file might be what you are looking for.

   <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
     <SyslogHost>YOUR HOST HERE</SyslogHost>
     <SuffixPattern>%mdc{applicationName} %msg</SuffixPattern>

   <root level="debug">
     <appender-ref ref="SYSLOG" />

You might also be interested in SiftingAppender which is a whole world on its 
own. See http://logback.qos.ch/manual/appenders.html#SiftingAppender

> Can the ContextJNDISelector use a configuration file outside of the war?


> Ideally I would have the logging configuration file in tomcat/conf or
> somewhere, and have all applications use the same one.

> Thanks for any help!

Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.

More information about the Logback-user mailing list