logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bender Heri" <HBen...@Ergonomics.ch>
Subject RE: my owen loggerclass
Date Thu, 13 Jul 2006 14:19:08 GMT
first, extending Logger class is discouraged. You should wrap the logger class if you want
to do generic work on each logger call. Best practice would be, to pass the correct logger
in each call to debug() etc. So you can benefit of finetuning the logger output by classes
and packages.

second: Your problem can be solved if you your wrapper class calls the generic method log()
of Logger. There you pass as first parameter the FQCN of your wrapper class:

public debug( Logger logger, Object object )
{
    // do your own stuff

    doLog( logger, Level.DEBUG, object, null );
}

private doLog( Logger logger, Level level, Obejct object, Throwable exception )
{
  logger.log( MyWrapperClass.class.getName(), level, object, exception );
}

The log4j framework will strip away all stack trace information up to this supplied FQCN.

Heri

> -----Original Message-----
> From: Strasser Christoph [mailto:christoph.strasser@vinzenzgruppe.at]
> Sent: Thursday, July 13, 2006 3:59 PM
> To: Log4J Users List
> Subject: [SPAM (Bayesain Analysis)] - my owen loggerclass - Bayesian
> Filter detected spam
> 
> 
> hi,
> 
>  
> 
> i need to write an owen logger class extending log4js logger and
> overwriting the debug, info, warn, error and fatal methods!
> 
>  
> 
> o.k. - i've done it like that:
> 
>  
> 
> public void debug(Object msg){
> 
> ...
> 
> my operations
> 
> ...
> 
>  
> 
> logger.debug(msg);  //logger is an object of log4js Logger
> 
> }
> 
>  
> 
> the problem is... i'm configuring my logger object in a 
> properties file,
> and i need to track the calling class and method (the methode 
> who starts
> the logging)... 
> 
>  
> 
> i used the patternlayouts litterals %C{1}.%M for getting the Class and
> Methods names... but now MY appender is the calling class and my debug
> method is the calling method... due to the command 
> 
> logger.debug(msg);  //logger is an object of log4js Logger
> 
>  
> 
> :(((
> 
>  
> 
> i've tried to replace the logger.debug(msg) thing with the 
> code, that is
> in the Logger.debug methode - hoping to get the initialli 
> calling class
> and methode... getting Nullpointers because of repository is Null... i
> tryed get rid of this problem by setting the repository... 
> but now... my
> loggerobject doesnt have an appender... but it should have one... here
> is the fragment of my code - can anyone help me with this?!?!
> 
>  
> 
> public void debug(Object msg){
> 
>             
> 
> ...
> 
> my operations
> 
> ...         
> 
>  
> 
> Logger logger = Logger.getLogger("myAppender");
> 
>  
> 
> Hierarchy hierarchy = new Hierarchy(logger);
> 
> repository = hierarchy;
> 
>       
> 
> if (repository.isDisabled(Level.DEBUG_INT)) {
> 
>   return;
> 
> }
> 
>  
> 
> if (Level.DEBUG.isGreaterOrEqual(logger.getEffectiveLevel())) {
> 
>   forcedLog(myLogger.class.getName(), Level.DEBUG, msg, null);
> 
> }
> 
> }
> 
> 

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


Mime
View raw message