[slf4j-dev] SLF4J Wrapper class line number incorrect

Ashley Westwell ashley.westwell at netoffice.ca
Wed Mar 4 16:30:07 CET 2009


Thanks it worked :)
      _____  

  From: Ralph Goers [mailto:rgoers at apache.org]
To: slf4j developers list [mailto:dev at slf4j.org]
Sent: Fri, 27 Feb 2009 02:10:08 -0500
Subject: Re: [slf4j-dev] SLF4J Wrapper class line number incorrect

  
  
You do something like this:
  

  
public class MyLogger {  

  
  private static final String FQCN = MyLogger.class.getName();  

  
  private LEVEL infoLevel = LEVEL.FINE;  
  private LEVEL debugLevel = LEVEL.FINE;  

  
  private Logger logger;  

  
  public MyLogger(Class clazz) {  
    logger = new LoggerWrapper(LoggerFactory.getLogger(clazz), FQCN);  
  }  

  
  public void info(LEVEL level, String format, Object[] argArray) {  
    if (!logger.isInfoEnabled() || !(level.ordinal() <= infoLevel.ordinal())) {  
     return;  
    }    
    if (logger.instanceofLAL) {  
      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);  
      ((LocationAwareLogger) logger).log(null, FQCN,  
          LocationAwareLogger.INFO_INT, formattedMessage, null);  
    } else {  
      logger.info(marker, format, arg1, arg2);  
    }    
  }  
}  
  

On Feb 26, 2009, at 5:49 PM, Ashley Westwell wrote:
    
  
Hey Ralph  
   
Took a look at the call and the wrapper class. My issue I dont want to esxpose the methods defined in the Logger interface. I only want to expose my methods for logging. Thats why I did not implement the Logger interface. Can you suggest how I could deal with the line number issue with out implementing Logger?  
   
Thanks
      _____  

  From: Ralph Goers [mailto:rgoers at apache.org]
To: slf4j developers list [mailto:dev at slf4j.org]
Sent: Fri, 20 Feb 2009 17:44:38 -0500
Subject: Re: [slf4j-dev] SLF4J Wrapper class line number incorrect

  
  
Take a look at XLogger in slf4j-ext.  

  
Out of curiosity, what do you need the wrapper for?  

Ralph  

  
On Feb 20, 2009, at 2:58 PM, Ashley Westwell wrote:
    
  
Good Afternoon

I have created a wrapper layer for SLF4J (Listed below). However the line number are incorrect, it is using the line numbers in the wrapper class not the class that I called the wrapper from. What is the correct way to fix this?

package com.test.commons.logging;

import com.test.commons.logging.LoggerFactory.LEVEL;

public class Logger {

    private LEVEL infoLevel = LEVEL.FINE;
    private LEVEL debugLevel = LEVEL.FINE;
    
    private org.slf4j.Logger logger = null;

    public Logger(Class clazz, LEVEL infoLevel, LEVEL debugLevel) {
        this.infoLevel = infoLevel;
        this.debugLevel = debugLevel;
        logger = org.slf4j.LoggerFactory.getLogger(clazz);
        
    }
    
    public Logger(String name, LEVEL infoLevel, LEVEL debugLevel) {
        this.infoLevel = infoLevel;
        this.debugLevel = debugLevel;
        logger = org.slf4j.LoggerFactory.getLogger(name);
    }
    
    public void info(String message) {
        logger.info(message);
    }
    
    public void info(String message, Throwable throwable) {
        logger.info(message, throwable);
    }
    
    public void info(String message, Object[] objects) {
        if(logger.isInfoEnabled()) {
            logger.info(message, objects);
        }
    }
    
    public void info(LEVEL level, String message) {
        if((logger.isInfoEnabled()) && (level.ordinal() <= infoLevel.ordinal())) {
            logger.info(message);
        }
    }
    
    public void info(LEVEL level, String message, Throwable throwable) {
        if((logger.isInfoEnabled()) && (level.ordinal() <= infoLevel.ordinal())) {
            logger.info(message, throwable);
        }
    }
    
    public void info(LEVEL level, String message, Object[] objects) {
        if((logger.isInfoEnabled()) && (level.ordinal() <= infoLevel.ordinal())) {
            logger.info(message, objects);
        }
    }
    
    // Debug messages.
    public void debug(String message) {
        if(logger.isDebugEnabled()) {
            logger.debug(message);
        }
        
    }
    public void debug(String message, Throwable throwable) {
        if(logger.isDebugEnabled()) {
            logger.debug(message, throwable);
        }
    }
    
    public void debug(String message, Object[] objects) {
        if(logger.isDebugEnabled()) {
            logger.debug(message, objects);
        }
    }
    
    public void debug(LEVEL level, String message) {
        if((logger.isDebugEnabled()) && (level.ordinal() <= debugLevel.ordinal())) {
                logger.debug(message);
        }
    }
    
    public void debug(LEVEL level, String message, Throwable throwable) {
        if((logger.isDebugEnabled()) && (level.ordinal() <= debugLevel.ordinal())) {
            logger.debug(message, throwable);
        }
    }

    public void debug(LEVEL level, String message, Object[] objects) {
        if((logger.isDebugEnabled()) && (level.ordinal() <= debugLevel.ordinal())) {
            logger.debug(message, objects);
        }
    }
    
    // The highest value; intended for extremely important messages (e.g. fatal program errors).
    public void severe(String message) {
        if(logger.isErrorEnabled()) {
            logger.error(message);
        }
    }
    
    public void severe(String message, Throwable throwable) {
        if(logger.isErrorEnabled()) {
            logger.error(message, throwable);
        }
    }
    
    public void severe(String message, Object[] objects) {
        if(logger.isErrorEnabled()) {
            logger.error(message, objects);
        }
    }
    
    // Intended for warning messages.
    public void warning(String message) {
        if(logger.isWarnEnabled()) {
            logger.warn(message);
        }
    }
    
    public void warning(String message, Throwable throwable) {
        if(logger.isWarnEnabled()) {
            logger.warn(message, throwable);
        }
    }
    
    public void warning(String message, Object[] objects) {
        if(logger.isWarnEnabled()) {
            logger.warn(message, objects);
        }
    }
    
}

    _____  

  
Notice: This email is confidential.  If you are not the intended recipient, please notify the sender by return email and delete this message from your mail box without reading or copying it or any attachments.

Attention: Ce courriel est confidentiel. Si vous n'êtes pas le destinataire prévu, veuillez en informer l'expéditeur par le courriel de retour et le supprimer immédiatement sans le lire ou le copier (incluant les pièces jointes,  le cas échéant).
_______________________________________________
dev mailing list
dev at slf4j.org
http://www.slf4j.org/mailman/listinfo/dev
  
   
 

    _____  

  
Notice: This email is confidential.  If you are not the intended recipient, please notify the sender by return email and delete this message from your mail box without reading or copying it or any attachments.

Attention: Ce courriel est confidentiel. Si vous n'êtes pas le destinataire prévu, veuillez en informer l'expéditeur par le courriel de retour et le supprimer immédiatement sans le lire ou le copier (incluant les pièces jointes,  le cas échéant).
_______________________________________________
dev mailing list
dev at slf4j.org
http://www.slf4j.org/mailman/listinfo/dev
      
   
 



Notice: This email is confidential.  If you are not the intended recipient, please notify the sender by return email and delete this message from your mail box without reading or copying it or any attachments.

Attention: Ce courriel est confidentiel. Si vous n'êtes pas le destinataire prévu, veuillez en informer l'expéditeur par le courriel de retour et le supprimer immédiatement sans le lire ou le copier (incluant les pièces jointes,  le cas échéant).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20090304/d0d73c85/attachment.htm>


More information about the slf4j-dev mailing list