So as an example?

class MyClass
{
        Logger eventLogger = Logger.getLogger("MyClass.EventLogger");
        Logger opsLogger = Logger.getLogger("MyClass.OpsLogger");


        void someMethod()
        {
                eventLogeger.warn("Server stoppped");
                opsLogger.warn("Server stoppped");
        }
}


Isn't that double the work now? What if I want to have the EventLogger writting 
to fileXYZ some "events" and then when I call OpsLogger.Warn() it sends out the 
e-mail and also writes the message to fileXYZ.

Is this logger nesting? I.e: my OpsLogger should be a child of EventLogger?

Thanks

-----Original Message-----
From: Curt Arnold [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 07, 2008 12:09 PM
To: Log4J Users List
Subject: Re: Understanding log levels



On May 7, 2008, at 10:22 AM, Tasso Angelidis wrote:

> Hi, I'm currently working on a custom level and logger to send my  
> operations team an e-mail when an error occurs or when an operation  
> log is explicitely written. For instance: logger.operations("Server  
> was shutdown manually.");
>
> If I call logger.error("...") The log is recorded in my error log  
> and an e-mail is sent. As expected.
> If I call logger.operations("...") The log is written to the error  
> and smtp appenders, when it should only be the SMTP appender. It  
> shouldn't be logged as an error.
>
> Have I done something wrong or is it simply a config issue?
>
> Thanks
>


The better way is to use the logger name to represent the audience or  
topic, not a custom level.  That is exactly what the logger hierarchy  
was designed to represent.  It is just that it is so common to use  
class names as topics that people think that is the only thing that a  
logger name can be.  This question is asked repeatedly in different  
forms, like http://permalink.gmane.org/gmane.comp.jakarta.log4j.user/15285 
.

My suggestion would be to have a separate logger named "operations." +  
class name and attach your SMTP appender to the operations logger.    
If you use the logger hierarchy as intended, you can use level as  
intended and allow for INFO, WARN or ERROR severities in your  
operations logging.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to