You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Deepal Mehta <me...@gmail.com> on 2010/08/05 16:27:09 UTC

Re: How to extend Logger Class

Paul Glezen <pglezen <at> us.ibm.com> writes:

> 
> 
> Hi Nidhi,
> The log4j distribution includes a "deepExtension.html" document in the docs 
directory.  It is a bit out of date (my fault), but it includes some tips for 
extending various portions of log4j.
> - Paul
> Paul Glezen
> Consulting IT Specialist
> IBM Software Services for WebSphere
> 818 539 3321
> AIM: pfglezenibm
> YIM: pfglezen
> ICQ: 179406599
> Please respond to "Log4J Developers List" <log4j-dev <at> logging.apache.org> 
> 
> To:	log4j-dev <at> logging.apache.orgcc:	 Subject:	How to extend 
Logger Class
> Hi 
> I am using Logger class in my project..BUt All the functions are of type 
static type and we cant override the static functions in subclasss..so how can 
i extend Logger class.Is there anyway..Please suggest me
> Thanx in advanceNidhi Garg
> Software Development Engineer (R&D)Barco | Control RoomsTel +91(0) (120) 242 
1651(10 Lines) Ext. 245Fax +91(0) (120) 242 1691 
> 

Hi,

  Try using the following code snippet

public class MyLogger
    extends Logger {
  
  static Logger logger;

//in the constructor, create the object of Logger class
  public RALogger(String name) {
    super (name);
    logger = this.getLogger(name);
    logger.setLevel(Level.ALL);
  }
 
//Override the methods and here you can massage the data as required by you 
before you print it...
  public void debug(Object message) { 
    logger.debug(message);
  }
  public void debug(Object message, Throwable t) { 
    logger.debug(message, t);
  }
  public void error(Object message) { 
    logger.error(message);
  }
  public void error(Object message, Throwable t) { 
    logger.error(message, t);
  }

  public void fatal(Object message) { 
    logger.fatal(message);
  }
  public void fatal(Object message, Throwable t) { 
    logger.fatal(message, t);
  }

  public void info(Object message) { 
    logger.info(message);
  }
  
  public void info(Object message, Throwable t) { 
    logger.info(message, t);
  }

  public void warn(Object message) { 
    logger.warn(message);
  }
  public void warn(Object message, Throwable t) { 
    logger.warn(message, t);
  }


}

Regards,
Deepal Mehta





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