File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do YOU use log4j

 
Charles Richardson
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic