• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How do YOU use log4j

 
Greenhorn
Posts: 8
  • 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
 
Villains always have antidotes. They're funny that way. Here's an antidote disquised as a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!