You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by s2...@yahoo.com on 2010/10/12 09:07:38 UTC

Extendening/wrapping Logger?


The code shown bellow was given as an example of how to extend Loger what I 
don't get is why logger was made a static field. Would this mean you would need 
a separate class for every instance?


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 extendLogger Class> Hi  > I am using 
Logger class in my project..BUt All the functions are of typestatic 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) 2421651(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
http://web.archiveorange.com/archive/v/uhq8tUYjy7IxiVqTYDg9