Ossec, jboss, log4j and syslog are on a plane…
As long as java is concerned you will always face the trouble of processing multi-line logs. It gets worse if you use ossec[1], a powerful log analyzer with real-time alerting. Ossec ships with default rules, especially rule 1002 “Unknown problem(s) in the system” that matches generic error-related words such as “critical|failure|segfault|error” against your logs.
Because of this rule, you’ll be sent tons of alerts when one of your java server/application prints a stacktrace and/or with multi-line entries that prints such words because you just can’t decode these log entries to know its java and create a decoder for it. Of course you can decode the first line in a multi-line entry, it has its own pattern (date with milliseconds etc), but you just can’t handle other line as they aren’t prefixed.
Sadly, using a FILE log4j appender to create something that resemble Syslog default formating using a custom patternLayout doesn’t work for stacktraces…
I think you are left with only one solution, to use a Syslog log4j appender, and use rsyslog templates capabilities to prefix each log line with something that resemble Syslog default formating and can be handled by ossec.
// Generate: 12 Apr 13:37:42 host.example.com jboss: applicative crap $template jbossFormat,"%timegenerated% host.example.com jboss: %msg%\n" local2.* /var/log/app/server.log;jbossFormat
That way, java (developers) can log anything, you can decode it accuratly:
<decoder name="jboss">
<program_name>jboss</program_name>
</decoder>
and choose to ignore stacktrace and false positive as follow:
<rule id="100002" level="0"> <if_sid>1002</if_sid> <decoded_as>jboss</decoded_as> <description>Ignoring unknown problems for Jboss logs</description> </rule>
[1] — http://www.ossec.net/