logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "None None" <japp...@hotmail.com>
Subject RE: Custom levels.
Date Fri, 08 Oct 2004 15:11:41 GMT
Hey I found that as well...

But I managed to make it work. It would help to say that the subclass folder 
in the samples is for the logger and that mycat.good is the properties file 
lol I

I like the logger method because it is losely coupled from the app. Anyways 
it's all good...

I need to understand how the levels work though...

In MyLevel class I have...
static public final int MANAGEMENT_INT = Level.FATAL_INT + 1;
private static String MANAGEMENT_STR = "MANAGEMENT";
public static final XLevel MANAGEMENT = new XLevel(MANAGEMENT_INT, 
MANAGEMENT_STR, 0); <---- What's the 3rd parameter for, the 0 (Zero)

Now I will explain the situation once more, so we understand each other and 
see why this is happening. ;)

I want my application that every time it starts/stops that it sends an 
e-mail. All "INFO" to go to a rolling file and all "FATAL" exceptions to 
e-mail.

So I have my properties file as follows...

log4j.rootLogger = INFO, file, mail

log4j.appender.file= org.apache.log4j.RollingFileAppender
log4j.appender.file.Threshold = INFO
log4j.appender.file.File = logs.txt
log4j.appender.file.MaxFileSize = 2KB
log4j.appender.file.MaxBackupIndex = 5
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-4r %-5p [%t] %37c %3x - 
%m%n

log4j.appender.mail = org.apache.log4j.net.SMTPAppender
log4j.appender.mail.Threshold = FATAL
log4j.appender.mail.SMTPHost = SOMESERVER
log4j.appender.mail.From = TMI.TestLogs
log4j.appender.mail.To = none@your.business
log4j.appender.mail.Subject = Application Exception
log4j.appender.mail.layout = org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern = %-4r %-5p [%t] %37c %3x - 
%m%n

Notice for now am not handeling the "MANAGEMENT" level I want

In MyLogger class I have written a management method that handles the new 
level I created. If you noticed above I set the new level to INT_FATAL + 1.

The problem now is when ever I write a "MANAGEMENT" message I get an e-mail, 
even though I set the appenders threshhold to "FATAL". If I configure 
another smtp appender for "MANAGEMENT" every time I write a "MANAGEMEN" 
message I will get 2 e-mails.

Thanks


>From: "DE BENEDICTIS DAVIDE" <ddebenedictis@sogei.it>
>Reply-To: "Log4J Users List" <log4j-user@logging.apache.org>
>To: "Log4J Users List" <log4j-user@logging.apache.org>
>Subject: RE: Custom levels.
>Date: Fri, 8 Oct 2004 15:48:24 +0200
>
> > -----Original Message-----
> > From: None None [mailto:jappdev@hotmail.com]
>
> > I already have a logger setup to send e-mails when "FATAL"
> > errors occur. But I also want to send e-mail on some specific
> > occasions ;) Like starting and stopping an application. To do
> > this I need to define a custom level. The problem is that the
> > samples provided for the custom level dont offer any
> > explanation on how to implement the logger class. Unless
> > there is a better way?
>
>Hi,
>I was starting doing a custom level but then I preferred the more light
>approach suggested from Yoav Shapira some time ago on this list.
>For me was perfect.
>Here there is the message:
>
>
> > -----Original Message-----
> > From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com]
> > Sent: Friday, September 17, 2004 1:59 PM
> > To: Log4J Users List
> > Subject: RE: Custom Levels
> >
> >
> > Hi,
> > I can't help with your actual problem, as I don't know its
> > cause, but I wanted to offer an alternative approach that
> > involves much less work for you.
> >
> > Use an Admin Logger as a separate Logger, rather than a
> > separate level.
> > Have a Singleton in your webapp which has
> >
> > private static final Logger ADMIN_LOGGER =
> > Logger.getLogger("MYAPP_ADMIN_LOGGER");
> >
> > public static Logger getAdminLogger() {
> >   return ADMIN_LOGGER;
> > }
> >
> > or maybe
> > public static void warnAdmin(...) {
> >   ADMIN_LOGGER.warn(...);
> > }
> > etc.
> >
> > The main advantage of this approach is that you don't need to
> > write a custom Level, a custom Logger, or a LoggerFactory.
> > In addition, you still maintain clean separation of logging
> > output for admin from other logging output.  You can still
> > configure whatever appenders (and thresholds, and renders,
> > etc.) you want just for the admin logger.  All your classes
> > can access it with negligible overhead via the singleton.
> > Much simpler, more streamlined than your approach, I think.
> > But it's just a suggestion, feel free to ignore it ;)
> >
> > Yoav Shapira
> > Millennium Research Informatics
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message