logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DE BENEDICTIS DAVIDE" <ddebenedic...@sogei.it>
Subject RE: Custom levels.
Date Fri, 08 Oct 2004 13:48:24 GMT
> -----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


Mime
View raw message