logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Krieg <akr...@marketaxess.com>
Subject RE: appenders in different levels? [newbie]
Date Tue, 26 Feb 2002 15:39:47 GMT
Markus,
	I have a logging system where only fatal errors are sent through an
SMTP handler and mailed to someone.  All messages are logged to the console.

To do this my config file looks like this:

log4j.rootLogger=debug, stdout,mail

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

#Use the SMTPAppender for mail
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.To=akrieg@marketaxess.com
log4j.appender.mail.From=testharness@marketaxess.com
log4j.appender.mail.Subject=A Fatal Harness Error Occurred
log4j.appender.mail.SMTPHost=myMailHost
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

#implement this class to only react to fatal or above errors
log4j.appender.mail.EvaluatorClass=com.adam.utils.MailEventEvaluator



Now we need to implement com.adam.utils.MailEventEvaluator which will cause
the SMTPHandler to only be used when we come across a fatal level message.


package com.adam.utils;

import org.apache.log4j.Level;
import org.apache.log4j.spi.TriggeringEventEvaluator;
import org.apache.log4j.spi.LoggingEvent;

/**
 *	This class isn used to send fatal error messages to a mail server as
per
 *	 Log4J TriggeringEventEvaluator functionality
 */
public class MailEventEvaluator implements TriggeringEventEvaluator {
    public boolean isTriggeringEvent (LoggingEvent event)  {
        return event.level.isGreaterOrEqual(Level.FATAL);
    }
}


Hope this helps,
Adam
-----Original Message-----
From: Markus Spath [mailto:mspath@arcor.de]
Sent: Tuesday, February 26, 2002 10:26 AM
To: log4j-user@jakarta.apache.org
Subject: appenders in different levels? [newbie]


Hi,

is it possible to add appenders to category definitions listening to
different 
log-levels (sorry if my terminology is awkward)

e.g.
to print only errors of a given Category to the ConsoleAppender, but
printing 
all messages to a RolingFileAppender?

(a workaround would be to define a seperate Category)


any examples (*.lcf) would be very helpful.

thanks,
Markus


--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message