aspose file tools*
The moose likes Other Open Source Projects and the fly likes How do  YOU  use log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How do  YOU  use log4j" Watch "How do  YOU  use log4j" New topic
Author

How do YOU use log4j

Charles Richardson
Greenhorn

Joined: Apr 28, 2004
Posts: 8
i was asked to retrofit a legacy codebase to use log4j vs. a home-grown logging class.
there are about two-dozen classes that inherit from one base class, yet the logger gets instantiated in one method, then passed around from method to method within the same class.
this is the case for each of the two-dozen subclasses in my charge.
i thought it would be appropriate to instantiate the logger in the base class, using a protected field, then let each subclass inherit that functionality.
the snag i've hit is that a small number of the subclasses are intended to be singletons and use only static methods and fields. not a problem (maybe?) except that i'm passing "this.getClass()" into log4j in the base class instantiation.
probably many of you are already saying, "you can't use 'this' in a static method" -- which is the reason i'm writing this post...
what is the best way to tackle this dilemma? i'm facing 29 compile errors about not being able to use 'this' in a static context, but i'm not so experienced in java that i know what to do?
is there something i can do to make a single base-class logger implementation work for both the static and non-static classes/methods/fields, or do i need 2 (or more?) solutions in order to satisfy all classes?
can i just eliminate the static keyword from the method(s) in question?
should i change my default name from this.getClass() to Class.getName() (or something similar)?
i'm trying to maximize the realized benefits from an o-o implementation but i'm stuck behind my relative inexperience/ignorance with java and log4j.
looking forward to your help...
richard
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do YOU use log4j