<font>Hi again.<br><br>As suggested I've implemented a POC on how SyslogAppender could be fixed, and have got it working. It resolves our issue. With the changes I made, the stacktrace lines can be prefixed as required, and with the proper configuration they now end up in the correct file on our logserver.<br>
<br>My configuration now looks like this:<br><br> <contextName>xxx-${CONTEXT_PATH}-${environment}</contextName><br> <appender name="LOGSERVER_FILE" class="no.xxx.logback.SyslogAppender"><br>
<contextName>xxx-${CONTEXT_PATH}-${environment}</contextName><br> <syslogHost>localhost</syslogHost><br> <facility>local3</facility><br> <SuffixPattern>%contextName %d{dd.MM.yyyy HH:mm:ss.SSS} [%p] [%c{1}] [%X{ThreadId}]: %m%n</SuffixPattern><br>
<StackTraceSuffixPattern>xxx-${CONTEXT_PATH}-${environment} - </StackTraceSuffixPattern><br> </appender><br><br>( Notice the new property </font><font><StackTraceSuffixPattern></font> )<br>
<br>All I had to change in the code (in SyslogAppender.java) was to implement a new member variable stackTraceSuffixPattern (plus getter/setter) and to append it in line 89 (after the prefix and before the tab). <br><br>In actual code I imagine you'd also want to add:<br>
-a null test, to make the new parameter optional<br>-the new property should be subjected to pattern convertion (this was not required for my POC to work, but would be nice/expected)<br><br><font>If someone would work with me and get this fix into logback proper it would be much appreciated. I can send/post working code. For how to best activate pattern conversion for the new property I would hope to get some help/guidance.<br>
<br>cheers,<br>Ingebrigt Berg<br><br></font><br><div class="gmail_quote">Den 14:48 30. mars 2012 skrev Ingebrigt Berg <span dir="ltr"><<a href="mailto:ingebrigt@jpro.no">ingebrigt@jpro.no</a>></span> følgende:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font>Hi !<br><br>We have looked more into this issue.<br><br>From a TCPdump for the traffic between the app (using logback) and the syslog-server we learn that each line in the stacktrace is actually sent as a separate message to syslog (sensitive info replaced with xx/yy/zz):<br>
<br>11:28:37.911604 IP xx<br> localhost.localdomain.55934 > localhost.localdomain.syslog: [bad udp cksum af4f!] SYSLOG, length: 101<br> Facility local3 (19), Severity error (3)<br> Msg: Mar 30 11:28:37 yy2-31 zz-mce-test 30.03.2012 11:28:37.910 [ERROR] [LogbackTester] []: Fjas\0x0a<br>
11:28:37.912028 IP xx<br> localhost.localdomain.55934 > localhost.localdomain.syslog: [bad udp cksum 6076!] SYSLOG, length: 104<br> Facility local3 (19), Severity error (3)<br> Msg: Mar 30 11:28:37 yy2-31 \0x09at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br>
<br>The first packet is a regular log statement, the second one is a line in a stack trace.<br><br>Notice how <br></font><font>'zz-mce-test 30.03.2012 11:28:37.910 [ERROR] [LogbackTester] []:'<br>is replaced with:<br>
</font><font> '\0x09at'</font><br><br>If we interpret this correctly, SyslogAppender will log the error message and each <font>StackTraceElement </font>separately. But for the <font>StackTraceElements </font>it will ignore what we configure in the <font><SuffixPattern> property:<br>
( </font><font><SuffixPattern>%contextName %d{dd.MM.yyyy HH:mm:ss.SSS} [%p] [%c{1}] [%X{ThreadId}]: %m%n</SuffixPattern> )<br>Instead the stackline messages simply get a </font><font>'\0x09at' (a TAB) appended in place of the </font><font>SuffixPattern</font><font>.<br>
<br>This happens in line 89 in ch.qos.logback.classic.net.SyslogAppender:<br>sb.append(prefix).append(CoreConstants.TAB).append(step);<br><br>Contrast that to line 59 </font><font>in ch.qos.logback.classic.net.SyslogAppender (normal messages), where the SuffixPattern gets added:</font><br>
<font>fullLayout.setPattern(prefixPattern + suffixPattern);<br><br></font><font>We see two viable solutions:<br><br>EITHER: <br>when a message is split into a main message and StackTraceElements, the </font><font>StackTraceElement messages must also get the content of the </font><font><SuffixPattern> appended<br>
<br>OR: <br>an optional property </font><font><StackTraceSuffixPattern></font> could be added to SyslogAppender, allowing control of what goes into <font>StackTraceElement messages.</font><br><font><br></font><font>cheers,<br>
Ingebrigt Berg + Marius Eikenes<br></font><font><br></font><br><div class="gmail_quote">Den 11:40 20. mars 2012 skrev Ingebrigt Berg <span dir="ltr"><<a href="mailto:ingebrigt@jpro.no" target="_blank">ingebrigt@jpro.no</a>></span> følgende:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font>Hi !<br><br>We've recently made the switch from Log4j to Logback.
We use Syslog to send logfiles to our logserver, and things generally
work.<br></font><font><br>But when there are stacktraces in the logs we get in trouble. SyslogAppender will replace lineshifts with '</font><font>#011</font>'
to make the logentry a single line. Then it will cut each line that is
to long according to the syslog limit of 2K/line. Only the fist segment
will arrive in the correct log. The remaining
segments are not prefixed with everything in the suffixPattern, and our
regexp will
not have anything to match. The segment will end up in a 'trash' log for
unmatchable loglines.<br>
<br><font>My config for the SyslogAppender looks like this:<br><br> <contextName>company-${CONTEXT_PATH}-${environment}</contextName><br> <appender name="LOGSERVER_FILE" class="ch.qos.logback.classic.net.SyslogAppender"><br>
<syslogHost>localhost</syslogHost><br> <facility>local3</facility><br> <SuffixPattern>%contextName %d{dd.MM.yyyy HH:mm:ss.SSS} [%p] [%c{1}] [%X{ThreadId}]: %m%n</SuffixPattern><br>
</appender><br><br>We use the contextName property to control the logfilename. On the receiving end we read the </font><font>contextName parameter (</font>using a regexp) <font>for each log line, and write the line to a file </font>with a corresponding name<font>.<br>
<br>We had a similar problem when we used Log4J (Where the Tag element
was used in the same manner), and fixed it back then by writing a custom
log4j SyslogAppender. But the main purpose of moving to Logback is to
loose all our home brew logging stuff, we don't want to go down that
path again. If we can't make Logback work out of the box with Syslog
we'll probably end up going back to Log4J. (Another alternative is to
replace Syslog with Gelf, but that's further down the road).<br>
<br>However, I imagine Logback and Syslog being a common combination,
and surely someone must have this working out of the box. Any advice
will be appreciated. My requirements are simple:<br>-must work with no custom logging code, only config (preferably xml)<br>
-stacktraces in logs must work<br>-must be able to fully control the filename on the recieving end.<br><br>cheers,<br>Ingebrigt Berg</font><font><br></font>
</blockquote></div></div></div><br>
</blockquote></div><br>