This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes extend Logger Class Log4J Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply Bookmark "extend Logger Class Log4J" Watch "extend Logger Class Log4J" New topic
Author

extend Logger Class Log4J

Arvindu
Greenhorn

Joined: Sep 30, 2002
Posts: 23
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
Pavan Panduga
Ranch Hand

Joined: Jun 12, 2002
Posts: 68
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

Joined: Sep 30, 2002
Posts: 23
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

Joined: Jun 12, 2002
Posts: 68
sure,
modify your XLevel calss from this


to



Regards,
Arvindu
Greenhorn

Joined: Sep 30, 2002
Posts: 23
Thanks Pavan cool
everything work as i needed..
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: extend Logger Class Log4J
 
Similar Threads
y this ClassCastException in log4j ?
java.util.Logger creating multiple log files
Refactoring - consequences of changing methods to static
log4j logging twice
Using Log4j efficiently