• 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

extend Logger Class Log4J

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to extend Logger Class like MyLogger

and add new Level like Trace

How to make the MyLogger.getLogger
to return MyLogger instance

MyLogger must extend Logger

Thanks in advance
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arvind,

If you want to define custom levels like TRACE, you could do this by writing a class which extends org.apache.log4j.Level.

there's an example,XLevel, in the log4j distribution. This is a subclass of Level and adds TRACE, LETHAL.

After writing a custom level class, there are two steps to follow. Configure this new calss, and fire custom log events.

1.Configuration
since, DEBUG is the default level, in order to print levels less than DEBUG should be configured.
my sample config file looks like this:


2. Using custom levels:



here's the output.



Hope that helps.

Regards,
 
Arvindu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pavan

It is very much helpful

I want my TRACE case come inbetween WARN and ERROR

DEBUG-->INFO-->WARN--->TRACE--->ERROR--->FATAL

Is it possible?
 
Pavan Panduga
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sure,
modify your XLevel calss from this


to



Regards,
 
Arvindu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pavan cool
everything work as i needed..
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic