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 Dave Hutz <dh...@extreme-messaging.com> on 2004/09/16 19:12:49 UTC

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

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

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

Posted by Niall Daley <ni...@apache.org>.
Dave,
	If you're trying to parse the log file on a periodic basic to look
for errors you'd be better off using the XML Layout as that will output
XML fragments which will contain all of the data, properly formatted.

	If you want to find the messages in real time instead then I'd
suggest using the UDP appender to send messages to your monitor process.
As each message will be sent in a datagram parsing should be straight
forward. There is an example of a simple receiver for the UDP appender in
the documentation for that appender.

Niall

On Thu, 16 Sep 2004, Dave Hutz 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
>

-- 
Niall Daley
Log4net Dev

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

Posted by Ceki Gülcü <ce...@qos.ch>.
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