{"id":20,"date":"2005-09-01T13:34:43","date_gmt":"2005-09-01T12:34:43","guid":{"rendered":"http:\/\/www.epischel.de\/wordpress\/?p=20"},"modified":"2014-03-02T23:35:48","modified_gmt":"2014-03-02T22:35:48","slug":"tomcat-and-syslog-and-accesslog","status":"publish","type":"post","link":"https:\/\/www.epischel.de\/wordpress\/2005\/09\/tomcat-and-syslog-and-accesslog\/","title":{"rendered":"Tomcat and syslog and access.log"},"content":{"rendered":"<p>A colleague of mine asked me how to route logging output of Jakarta Tomcat 5.0 to Unix syslog. This is rather easy since tomcat uses a library called &#8222;<a href=\"http:\/\/jakarta.apache.org\/commons\/logging\/index.html\">jakarta commons logging<\/a>&#8220; which in turn can use &#8222;<a href=\"http:\/\/logging.apache.org\/log4j\/1.2\/\">log4j<\/a>&#8220; which itself can log to Unix Syslog.<\/p>\n<p>First, download <a href=\"http:\/\/logging.apache.org\/log4j\/1.2\/download.html\">log4j<\/a> and <a href=\"http:\/\/commons.apache.org\/proper\/commons-logging\/download_logging.cgi\">commons-logging<\/a>. Now copy log4j-1.2.x.jar and commons-logging.jar to tomcats common\/lib directory. Create a file &#8222;log4j.properties&#8220; in tomcats common\/classes directory with the following content:<\/p>\n<pre>log4j.rootLogger=INFO,sysout,syslog\r\n\r\n# sysout = Konsole\r\nlog4j.appender.sysout=org.apache.log4j.ConsoleAppender\r\nlog4j.appender.sysout.layout=org.apache.log4j.PatternLayout\r\nlog4j.appender.sysout.layout.ConversionPattern=%d{ISO8601} %-5p [%t] [%c] %m%n\r\n\r\n####\r\n# Configuration for syslog\r\n##\r\n# syslog = Syslog\r\nlog4j.appender.syslog=org.apache.log4j.net.SyslogAppender\r\n# which Syslog-Facility is going to be used\r\n# for valid values see\r\n# http:\/\/logging.apache.org\/log4j\/docs\/api\/apache\/log4j\/net\/SyslogAppender.html#getFacility(java.lang.String)\r\nlog4j.appender.syslog.facility=LOCAL0\r\nlog4j.appender.syslog.layout.ConversionPattern=%-5p [%t] [%c]: %m%n\r\nlog4j.appender.syslog.layout=org.apache.log4j.PatternLayout\r\n# enter your host here\r\nlog4j.appender.syslog.SyslogHost=localhost<\/pre>\n<p>This log4j.properties configures log4j for writing to standard-output as well as to syslog-daemon, facility LOCAL0. You may change the logging format according to the <a href=\"http:\/\/logging.apache.org\/log4j\/1.2\/apidocs\/org\/apache\/log4j\/PatternLayout.html\">documentation<\/a>. If you want to disable logging to standard-output, remove &#8222;sysout&#8220; from the first line in log4j.properties.<\/p>\n<p>There are more <a href=\"http:\/\/minaret.biz\/tips\/tomcatLogging.html\">tips as well as a list of Log-Identifiers<\/a> in Tomcat 5.0.27 .<\/p>\n<p>My colleague had one more wish: to redirect the access.log to syslog. This is more of a problem since the default tomcat implementation of access-logging (called AccessLogValve) uses direct file access instead of using common-loggings. Since it is open source, I took that implementation and replaced that file access to a common-loggings call. Download <a href=\"\/misc\/accessLogging.jar\">this tiny jar<\/a> and place it in tomcats server\/lib (not common\/lib !!). Replace your usual &#8222;org.apache.catalina.valves.AccessLogValve&#8220; with &#8222;de.epischel.tomcat.LoggingAccessLogValve&#8220;. The logging name &#8222;tomcat.accesslog&#8220; and INFO-level is used and you can assign a different output destination (called appender) in log4j.properties:<\/p>\n<pre>log4j.additivity.tomcat.accesslog=false\r\nlog4j.logger.tomcat.accesslog=INFO,syslog2<\/pre>\n<p>where syslog2 may e.g. be a syslog appender like &#8222;syslog&#8220; above but with a different facility or a different syslog-host.<\/p>\n<p>Task done. \ud83d\ude42<\/p>\n<div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"<p>A colleague of mine asked me how to route logging output of Jakarta Tomcat 5.0 to Unix syslog. This is rather easy since tomcat uses a library called &#8222;jakarta commons logging&#8220; which in turn can use &#8222;log4j&#8220; which itself can log to Unix Syslog. First, download log4j and commons-logging. Now copy log4j-1.2.x.jar and commons-logging.jar to&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[3],"tags":[120],"series":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","kind-"],"kind":false,"_links":{"self":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":5,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":542,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/20\/revisions\/542"}],"wp:attachment":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/tags?post=20"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/series?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}