• 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 to encapsulate Logger info

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
im using the log4j logger , but now i like to do generic Logger to my application
and encapsulate all the log4j initial data it needed in some generic Logger class
my first proablem is for example if i call from my class this generic Logger how can it know
my class name whiteout passing it the "MyClass.class" as parameter so log4j could use this information?

for example the code :


thanks for your help
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of

you could write something like

Then you wouldn't need to pass the class name along.

Your logging class could also examine the current stack trace, where the second-but-last entry would be the calling class and method. You can get the stack trace via "new Throwable().getStackTrace()".

But why do you want to roll your own logging abstraction, when something like Jakarta Commons Logging is available, which can wrap java.util.logging, log4j, and other logging implementations?
[ November 12, 2006: Message edited by: Ulf Dittmer ]
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seams not to work in static method

the getClass().getName()

is there way to overcome this ? my method have to be static
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the shortcut MyClass.class, which should work in a static method as well.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic