logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Womack <wom...@adobe.com>
Subject RE: How to use Log4J in Multiple classes? App Design?
Date Wed, 13 Jul 2005 00:10:58 GMT
The assumption here is that you have named your classes and packages in some
coherent, logical, useful fashion, as in:

com.mycompany.package1.classA
com.mycompany.package1.classB 
com.mycompany.package2.classC
com.mycompany.package2.classD

If you do this, then this gives you maximum flexibility in the configuration
file to control log output by specific class or an entire (related)
package...

Hth,
-Mark

> -----Original Message-----
> From: Paul Smith [mailto:psmith@aconex.com]
> Sent: Tuesday, July 12, 2005 5:03 PM
> To: Log4J Users List
> Subject: Re: How to use Log4J in Multiple classes? App Design?
> 
> I would really suggest you follow the standard pattern and have one
> Logger per class ala:
> 
> public class MyClass {
> 
>    private static final Logger LOG = Logger.getLogger(MyClass.class);
> 
> ....
> 
> 
> Let each class log it's own stuff.
> 
> Paul Smith
> 
> On 13/07/2005, at 9:57 AM, John Hurt wrote:
> 
> > Hi,
> >
> > My application is split up into multiple classes. If I had
> > processing in
> > each class that I wanted to log, what's the best way to make a
> > reference to
> > the Logger available, so that for instance they all write to the
> > same log
> > file?
> >
> > Do I create an instance of the Logger class at the beginning of the
> > program
> > flow, then pass that class to all the methods/classes that plan to do
> > logging?
> >
> > Do I make a wrapper singleton class that has a Logger in it and all
> > code
> > refers to the wrapper class?
> >
> > Do I use a base class (or interface or abstract class) that includes a
> > reference to a Logger class?
> >
> > Anyone has generic examples where Logger is used in more than 1
> > class, how
> > to use it gracefully? Thanks.
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


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