You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Ceki Gülcü <ce...@qos.ch> on 2004/09/16 20:43:03 UTC

Re: Parsing of log files from FileAppender/Supporting exceptions in the PatternLayout

Hello,

In the current (log4j) code, if you are using the PatternLayout,
exceptions are handled by the appender instead of the
PatternLayout. At the time, it was assumed that the user would always
want to see the exception and it would be error prone for force the
user to specify an exception converter, say %e, at the end of the
conversion pattern. Although not very coherent architecturally, this
choice has worked reasonably well.

Adding a pattern converter to handle the %e specifier should be
easy. The only difficulty may arise in returning the correct value in
ignoresThrowable() for all cases.

For example, if the pattern is "%m%n%e", then ignoresThrowable() for
the PatternLayout should return false, but if the pattern is "%m%n",
then ignoresThrowable() should return true. This can be achieved by
having each PatternConverter inform the PatternLayout instance of
whether it handles exceptions or not.

Anyway, your question justifies adding a PatternConverter to handle
the %e case.

Hope this helps,

At 07:12 PM 9/16/2004, you wrote:
>We are trying to setup some automated alarming when errors are written to
>our log files.
>The problem we are having is that the message span multiple lines, with no
>obvious beginning or end to each message.
>I tried adding literals at the beginning and end of the conversion
>pattern, but that didn't work because the exception is written after the
>end of the pattern.
>
>The best solution I could think of is to support a pattern ("%e"?) for the
>exception string in the PatternLayout.
>If the pattern contains %e, the layout would return false for
>IgnoresException, and it would render the exception as part of the
>pattern, which would let the end marker come after the exception.
>If the pattern does contains %e, it would return true for
>IgnoresException, and the behavior would be unchanged.
>
>Make sense?
>
>Has anybody done this?
>If not, if I do it will somebody commit it?
>
>Thanks,
>         Dave

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp