Apache Tomcat and Logging – The 3rd

By | July 18, 2013

My never ending story with Tomcat and logging.  The previous posts are here and here. This version has two updates.

  1. Tomcat was still sending the System.out and System.err streams to the shell and eventually to catalina.out in the normal configuration.  The jar file now contains a life cycle listener which can be used to redirect those to syslogd as well.  Just add a line like <Listener className=”org.apache.log4j.contrib.ServerLifecycleListener” /> to the to of the server.xml after all the other <Listener> elements. The new streams will show up as [stderr] and [stdout].
  2. We use JRuby on Rails inside our Tomcat. That setup sticks sometimes many lines including ‘\n’s and terminal color codes into one logging message. The normal  SyslogAppender class will split the message based on the maximum length for syslogd. But that does create messages which are hard to read. So I created a subclass of the org.apache.log4j.net.SyslogAppender, called org.apache.log4j.net.NlSplitSyslogAppender, which splits any message on ‘\n’ and also cleans up all the terminal codes which just add clutter to the syslogd messages. Just replace the org.apache.log4j.net.SyslogAppender with org.apache.log4j.net.NlSplitSyslogAppender in your log4j.properties to play with it.

The updated jar with all the sources is mw-syslog.jar. Maybe I’ll create a github repo eventually for this. Every time I hope it’s the last change, but I come back to again and again.

As always, have fun,

4 thoughts on “Apache Tomcat and Logging – The 3rd

  1. Pingback: Apache Tomcat and Logging – The 2nd - Marco's Corner

  2. eastheroro

    hi, good job. I have tested in tomcat6, test passed. could you tell me how to build for tomcat5, in my environment, there are many tomcat5. thank you very much

  3. admin Post author

    I did not look at Tomcat5 in a very long time. So I can’t really help you there:-(

  4. jbrown9001

    hey i know it’s been a long time since you worked on this, but i’m actually looking at using this. any chance you can update the github repo with the latest files? i tested it as well and it seems to work really nicely.
    can you put a license on this project as well? (GPL or Apache maybe)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.