logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Joshua.P.Willi...@alltel.com>
Subject RE: Best practice on declaring Loggers
Date Tue, 13 Jun 2006 14:12:33 GMT
I'm new to JAVA and log4j, but I created a singleton object to be my logger that is used by
all the classes in a single threaded project I'm working on.. Is this bad?  I suppose I didn't
know how to use the log4j api correctly, but I was getting duplicate records in my logs, so
I created a singleton object that every other object uses and it solved my problem (no more
duplicate entries in my logs).

-----Original Message-----
From: Konstantinos Karadamoglou [mailto:kkarad@googlemail.com]
Sent: Tuesday, June 13, 2006 8:19 AM
To: Log4J Users List
Subject: Re: Best practice on declaring Loggers


thank you Javier!

On 13/06/06, Javier Gonzalez <jagonzal@gmail.com> wrote:
>
> I usually like to declare them private static final. Private because I
> don't want any other class accessing the logger, and static final to
> keep it "separate" from the class instances.
>
> The exception being when you are subclassing, then it is useful to
> declare the logger on the superclass like this:
>
> private Logger log = Logger.getLogger(getClass());
>
> That way, if you execute an inherited method, the log appears as
> coming from your own class and not from the superclass.
>
> On 6/13/06, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
> > Hello all,
> >
> > Which is the best practice of declaring Loggers? For instance, should
> they
> > be static, private, final? and why?
> >
> > Thank you in advance, Kostas
> >
> >
>
>
> --
> Javier González Nicolini
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

******************************************************************************************
The information contained in this message, including attachments, may contain 
privileged or confidential information that is intended to be delivered only to the 
person identified above. If you are not the intended recipient, or the person 
responsible for delivering this message to the intended recipient, ALLTEL requests 
that you immediately notify the sender and asks that you do not read the message or its 
attachments, and that you delete them without copying or sending them to anyone else. 



---------------------------------------------------------------------
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