• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do YOU use log4j

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic