You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ramdas Hegde <ra...@onyx-systems.com> on 2003/06/16 22:35:45 UTC

How to create customized Levels

I have a requirement wherein I need to log information not using the
standard Levels but a customized level . I have readin the mailing archives
about people who have extended the Level and Logger classes to achieve this.
I have also read warning saying that extending the Level class is not
advisable.
Can someone suggest an alternative to extending Level to achieve my goal of
using a customized level?

Thanks

Ramdas


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: How to create customized Levels

Posted by Yoav Shapira <yo...@yahoo.com>.
Howdy,
Extension / subclassing:

public class MyLevel extends Level {
...
}

Wrapping:

public class MyLogger {
  private Logger theLogger;

  // My extended methods here
}

I'm not sure what Senor Qin meant in the Servlet listener idea, as that's not
even close to the right granularity or context if I correctly understood your
requirement.

Regarding your layout question: of course it's possible to remove [info] from
the layout: use a PatternLayout without %p in it.

Your use case itself is interested.  We too include performance-related logging
statements, and we keep them at debug level.  It's true that enabling
debug-level logging for the relevant classes at runtime gives us extra
information beyond the performance statistics.  However, we just use grep to
extract what we need (e.g. grep for "elapsed time"), and that works well for
us.  I much prefer a simple technique like that to customizing an external
component, but that's just me.

Yoav Shapira

--- Ramdas Hegde <ra...@onyx-systems.com> wrote:
> Ceki
> 
> What exactly do you mean by wrapping Logger? I have been able to extend
> Level to include my customized level.
> 
> Thanks
> 
> Ramdas
> 
> -----Original Message-----
> From: Ceki Gulcu [mailto:ceki@qos.ch]
> Sent: Monday, June 16, 2003 2:00 PM
> To: Log4J Users List
> Subject: Re: How to create customized Levels
> 
> 
> At 01:35 PM 6/16/2003 -0700, you wrote:
> >I have a requirement wherein I need to log information not using the
> >standard Levels but a customized level . I have readin the mailing archives
> >about people who have extended the Level and Logger classes to achieve
> this.
> >I have also read warning saying that extending the Level class is not
> >advisable.
> 
> Ramdas,
> 
> Extending Logger is not advisable while extending Level is fine.
> Try wrapping Logger and extending Level.
> 
> >Can someone suggest an alternative to extending Level to achieve my goal of
> >using a customized level?
> >
> >Thanks
> >
> >Ramdas
> 
> --
> Ceki  For log4j documentation consider "The complete log4j manual"
>        ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp
> 
>        In the USA the log4j manual is carried by Softpro books.
>        http://store.yahoo.com/softpro/2-9700369-0-8.html
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> 


=====
Yoav Shapira
yoavs@computer.org

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: How to create customized Levels

Posted by Ramdas Hegde <ra...@onyx-systems.com>.
Ceki

What exactly do you mean by wrapping Logger? I have been able to extend
Level to include my customized level.

Thanks

Ramdas

-----Original Message-----
From: Ceki Gulcu [mailto:ceki@qos.ch]
Sent: Monday, June 16, 2003 2:00 PM
To: Log4J Users List
Subject: Re: How to create customized Levels


At 01:35 PM 6/16/2003 -0700, you wrote:
>I have a requirement wherein I need to log information not using the
>standard Levels but a customized level . I have readin the mailing archives
>about people who have extended the Level and Logger classes to achieve
this.
>I have also read warning saying that extending the Level class is not
>advisable.

Ramdas,

Extending Logger is not advisable while extending Level is fine.
Try wrapping Logger and extending Level.

>Can someone suggest an alternative to extending Level to achieve my goal of
>using a customized level?
>
>Thanks
>
>Ramdas

--
Ceki  For log4j documentation consider "The complete log4j manual"
       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp

       In the USA the log4j manual is carried by Softpro books.
       http://store.yahoo.com/softpro/2-9700369-0-8.html


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: How to create customized Levels

Posted by Ceki Gülcü <ce...@qos.ch>.
At 01:35 PM 6/16/2003 -0700, you wrote:
>I have a requirement wherein I need to log information not using the
>standard Levels but a customized level . I have readin the mailing archives
>about people who have extended the Level and Logger classes to achieve this.
>I have also read warning saying that extending the Level class is not
>advisable.

Ramdas,

Extending Logger is not advisable while extending Level is fine.
Try wrapping Logger and extending Level.

>Can someone suggest an alternative to extending Level to achieve my goal of
>using a customized level?
>
>Thanks
>
>Ramdas

--
Ceki  For log4j documentation consider "The complete log4j manual"
       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp

       In the USA the log4j manual is carried by Softpro books.
       http://store.yahoo.com/softpro/2-9700369-0-8.html


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org