
Thanks for the suggestions, this is exactly what I want to do. As long as I can point ContextJNDISelector to an external config file, it sounds perfect. I assume I just put in the full path to get at a resource outside of the war? I have tried setting MDC with log4j in the first Listener for a web app. This, unfortunately, has led to unpredictable results. Sometimes it comes through, sometimes not. We are running on a Tomcat 6 cluster. I'll give Logback a try, and hope the dropping MDC is a log4j issue. I had suspected maybe it was the way tomcat created threads that the parent MDC was sometimes not propagating. I assume setting the MDC in the first <listener> in web.xml should make it globally available, and applied to all logging statements? Thanks! On 2/11/09 10:31 AM, "Ceki Gulcu" <ceki@qos.ch> wrote:
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.
<configuration> <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender"> <SyslogHost>YOUR HOST HERE</SyslogHost> <Facility>USER</Facility> <SuffixPattern>%mdc{applicationName} %msg</SuffixPattern> </appender>
<root level="debug"> <appender-ref ref="SYSLOG" /> </root> </configuration>
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?
Sure.
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!