You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2001/03/19 17:40:29 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/util/logger Logger.java SimpleLogger.java

juergen     01/03/19 08:40:29

  Modified:    src/share/org/apache/slide/common Domain.java
               src/wrappers/log4j Log4jLogger.java
               src/share/org/apache/slide/util/logger Logger.java
                        SimpleLogger.java
  Log:
  1) Added various isEnabled methods
  2) mapped the channel specification to the log4j category (not available in SimpleLogger)
  3) moved package of log4JWrapper (for easy compilation)
  
  Revision  Changes    Path
  1.19      +65 -5     jakarta-slide/src/share/org/apache/slide/common/Domain.java
  
  Index: Domain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Domain.java	2001/02/15 17:33:10	1.18
  +++ Domain.java	2001/03/19 16:40:26	1.19
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v 1.18 2001/02/15 17:33:10 remm Exp $
  - * $Revision: 1.18 $
  - * $Date: 2001/02/15 17:33:10 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Domain.java,v 1.19 2001/03/19 16:40:26 juergen Exp $
  + * $Revision: 1.19 $
  + * $Date: 2001/03/19 16:40:26 $
    *
    * ====================================================================
    *
  @@ -88,7 +88,7 @@
    * For now, does not implement access control on Namespaces.
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.18 $
  + * @version $Revision: 1.19 $
    */
   public final class Domain {
       
  @@ -331,6 +331,66 @@
       public static void warn(Object data) {
           log(data, Logger.WARNING);
       }
  +        
  +    
  +    /**
  +     * Check if the channel with the specified level is enabled for logging.
  +     * This implementation ignores the channel specification
  +     *
  +     * @param channel The channel specification
  +     * @param level   The level specification
  +     */
  +
  +    public static boolean isEnabled(String channel, int level) {
  +        return logger.isEnabled(channel, level);
  +    }
  +            
  +        
  +    
  +    /**
  +     * Check if the default channel with the specified level is enabled for logging.
  +     *
  +     * @param level   The level specification
  +     */
  +
  +    public static boolean isEnabled(int level) {
  +        return logger.isEnabled(level);
  +    }
  +
  +    
  +    /**
  +     * Check if the default channel with the DEBUG level is enabled for logging.
  +     */
  +
  +    public static boolean isDebugEnabled() {
  +        return isEnabled(logger.DEBUG);
  +    }
  +    
  +    /**
  +     * Check if the default channel with the WARNING level is enabled for logging.
  +     */
  +
  +    public static boolean isWarningEnabled() {
  +        return isEnabled(logger.WARNING);
  +    }
  +    
  +    /**
  +     * Check if the default channel with the INFO level is enabled for logging.
  +     */
  +
  +    public static boolean isInfoEnabled() {
  +        return isEnabled(logger.INFO);
  +    }
  +    
  +    /**
  +     * Check if the default channel with the ERROR level is enabled for logging.
  +     */
  +
  +    public static boolean isErrorEnabled() {
  +        return isEnabled(logger.ERROR);
  +    }
  +            
  +    
       
       
       // -------------------------------------------------------- Package Methods
  @@ -488,7 +548,7 @@
               
               Logger namespaceLogger = null;
               try {
  -                namespaceLogger = 
  +                namespaceLogger =
                       (Logger) (Class.forName(loggerClass).newInstance());
                   namespaceLogger.setLoggerLevel(configuration.getAttributeAsInt
                                                  ("logger-level", Logger.INFO));
  
  
  
  1.2       +105 -42   jakarta-slide/src/wrappers/log4j/Log4jLogger.java
  
  Index: Log4jLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/wrappers/log4j/Log4jLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Log4jLogger.java	2001/02/12 05:49:13	1.1
  +++ Log4jLogger.java	2001/03/19 16:40:27	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/wrappers/log4j/Log4jLogger.java,v 1.1 2001/02/12 05:49:13 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/02/12 05:49:13 $
  + * $Header: /home/cvs/jakarta-slide/src/wrappers/log4j/Log4jLogger.java,v 1.2 2001/03/19 16:40:27 juergen Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/03/19 16:40:27 $
    *
    * ====================================================================
    *
  @@ -61,7 +61,7 @@
    *
    */
   
  -package wrappers.log4j;
  +package log4j;
   
   import java.util.Date;
   import java.util.Locale;
  @@ -80,29 +80,13 @@
       // ----------------------------------------------------- Instance Variables
       
       
  -    /**
  -     * Log4j category.
  -     */
  -    private Category cat;
  -    
       
  -    /**
  -     * Logger level.
  -     */
  -    private int loggerLevel;
  -    
  -    
  -    /**
  -     * Name.
  -     */
  -    private String name;
       
  -    
       // ----------------------------------------------------- Static Initializer
       
       
       static {
  -        BasicConfigurator.configure();
  +//      BasicConfigurator.configure();
       }
       
       
  @@ -114,26 +98,45 @@
        *
        * @param loggerLevel New logger level
        */
  -    public void setLoggerLevel(int loggerLevel) {
  -        this.loggerLevel = loggerLevel;
  +    public void setLoggerLevel(String channel, int loggerLevel) {
           Priority priority = toPriority(loggerLevel);
  -        if (cat != null) {
  -            cat.setPriority(priority);
  -        }
  +        Category cat = getCategory(channel);
  +        cat.setPriority(priority);
  +    }
  +    
  +    /**
  +     * Logger level setter.
  +     *
  +     * @param loggerLevel New logger level
  +     */
  +    public void setLoggerLevel(int loggerLevel) {
  +        setLoggerLevel(DEFAULT_CHANNEL, loggerLevel);
       }
       
       
       /**
  -     * Set name.
  +     * Logger level getter.
  +     *
  +     * @return int logger level
        */
  -    public void setName(String name) {
  -        this.name = name;
  -        cat = Category.getInstance(name);
  -        Priority priority = toPriority(loggerLevel);
  -        cat.setPriority(priority);
  +    public int getLoggerLevel(String channel) {
  +        Category cat = getCategory(channel);
  +        return fromPriority(cat.getPriority());
       }
       
       
  +    /**
  +     * Logger level getter.
  +     *
  +     * @return int logger level
  +     */
  +    public int getLoggerLevel() {
  +        return getLoggerLevel(DEFAULT_CHANNEL);
  +    }
  +    
  +    
  +    
  +    
       // --------------------------------------------------------- Logger Methods
       
       
  @@ -145,13 +148,8 @@
        * @param level The level used for logging.
        */
       public void log(Object data, String channel, int level) {
  -        if (cat == null) {
  -            cat = Category.getInstance("Slide");
  -            Priority priority = toPriority(loggerLevel);
  -            cat.setPriority(priority);
  -        }
  -        Priority priority = toPriority(level);
  -        cat.log(priority, data);
  +        Category cat = getCategory(channel);
  +        cat.log(toPriority(level), data);
       }
       
       
  @@ -162,7 +160,7 @@
        * @param level The level used for logging.
        */
       public void log(Object data, int level) {
  -        this.log(data, "default", level);
  +        this.log(data, DEFAULT_CHANNEL, level);
       }
       
       
  @@ -172,11 +170,48 @@
        * @param data The object to log.
        */
       public void log(Object data) {
  -        this.log(data, "default", Logger.DEBUG);
  +        this.log(data, DEFAULT_CHANNEL, Logger.DEBUG);
       }
       
  +        
  +    
  +    /**
  +     * Check if the channel with the specified level is enabled for logging.
  +     * This implementation ignores the channel specification
  +     *
  +     * @param channel The channel specification
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(String channel, int level) {
  +        Category cat = getCategory(channel);
  +        return cat.isEnabledFor(toPriority(level));
  +    }
  +            
  +        
  +    
  +    /**
  +     * Check if the default channel with the specified level is enabled for logging.
  +     *
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(int level) {
  +        return isEnabled(DEFAULT_CHANNEL, level);
  +    }
  +            
  +    
  +    
  +    
  +    // ------------------------------------------------------ Private/Protected Methods
       
  -    // ------------------------------------------------------ Protected Methods
  +    private Category getCategory(String channel) {
  +        Category cat = Category.exists(channel);
  +        if (cat == null) {
  +            cat = Category.getInstance(channel);
  +        }
  +        return cat;
  +    }
       
       
       /**
  @@ -211,5 +246,33 @@
           return result;
       }
       
  +    
  +    /**
  +     * Convert Slide priority to log4j priority.
  +     */
  +    protected int fromPriority(Priority priority) {
  +        int result = INFO;
  +        
  +        if (priority.equals(Priority.FATAL)){
  +            result = EMERGENCY;
  +        }
  +        else if (priority.equals(Priority.ERROR)){
  +            result = ERROR;
  +        }
  +        else if (priority.equals(Priority.WARN)){
  +            result = WARNING;
  +        }
  +        else if (priority.equals(Priority.INFO)){
  +            result = INFO;
  +        }
  +        else if (priority.equals(Priority.DEBUG)){
  +            result = DEBUG;
  +        }
  +        else {
  +            result = INFO;
  +        }
  +        
  +        return result;
  +    }
       
   }
  
  
  
  1.3       +67 -5     jakarta-slide/src/share/org/apache/slide/util/logger/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/Logger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Logger.java	2001/01/24 17:42:28	1.2
  +++ Logger.java	2001/03/19 16:40:28	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/Logger.java,v 1.2 2001/01/24 17:42:28 juergen Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/01/24 17:42:28 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/Logger.java,v 1.3 2001/03/19 16:40:28 juergen Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/03/19 16:40:28 $
    *
    * ====================================================================
    *
  @@ -72,7 +72,7 @@
    * The six levels used for logging are (in order of gravity): EMERGENCY,
    * CRITICAL, ERROR, WARNING, INFO and DEBUG.
    *
  - * @version 1.0 (CVS $Revision: 1.2 $ $Date: 2001/01/24 17:42:28 $)
  + * @version 1.0 (CVS $Revision: 1.3 $ $Date: 2001/03/19 16:40:28 $)
    * @author <a href="mailto:scoobie@pop.systemy.it">Federico Barbieri</a>
    * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  @@ -222,6 +222,16 @@
       public static final int DEBUG=7;
       
       
  +    /**
  +     * Specify the default string for logging without a channel.
  +     *
  +     * @param data The object to log.
  +     * @param channel The channel name used for logging.
  +     * @param level The level used for logging.
  +     */
  +    public static String DEFAULT_CHANNEL = "org.apache.slide.util.logger";
  +    
  +    
       // ------------------------------------------------------ Interface Methods
       
       
  @@ -254,11 +264,63 @@
           
       
       /**
  -     * Log an object.
  +     * Set the logger level for the default channel
        *
        * @param data The object to log.
        */
   
       public void setLoggerLevel(int level);
  +    
  +    
  +            
  +    /**
  +     * Set the logger level for the specified channel
  +     *
  +     * @param data The object to log.
  +     */
  +
  +    public void setLoggerLevel(String channel, int level);
  +    
  +        
  +    
  +    /**
  +     * Get the logger level for the default channel
  +     *
  +     * @param data The object to log.
  +     */
  +
  +    public int getLoggerLevel();
  +    
  +    
  +            
  +    /**
  +     * Get the logger level for the specified channel
  +     *
  +     * @param data The object to log.
  +     */
  +
  +    public int getLoggerLevel(String channel);
  +            
  +    
  +        
  +    
  +    /**
  +     * Check if the channel with the specified level is enabled for logging.
  +     *
  +     * @param channel The channel specification
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(String channel, int level);
  +            
  +        
  +    
  +    /**
  +     * Check if the default channel with the specified level is enabled for logging.
  +     *
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(int level);
               
   }
  
  
  
  1.5       +57 -8     jakarta-slide/src/share/org/apache/slide/util/logger/SimpleLogger.java
  
  Index: SimpleLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/SimpleLogger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleLogger.java	2001/01/24 17:52:24	1.4
  +++ SimpleLogger.java	2001/03/19 16:40:28	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/SimpleLogger.java,v 1.4 2001/01/24 17:52:24 juergen Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/01/24 17:52:24 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/SimpleLogger.java,v 1.5 2001/03/19 16:40:28 juergen Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/03/19 16:40:28 $
    *
    * ====================================================================
    *
  @@ -106,17 +106,38 @@
        *
        * @param loggerLevel New logger level
        */
  -    public void setLoggerLevel(int loggerLevel) {
  +    public void setLoggerLevel(String channel, int loggerLevel) {
           this.loggerLevel = loggerLevel;
       }
       
       
       /**
  +     * Logger level setter.
  +     *
  +     * @param loggerLevel New logger level
  +     */
  +    public void setLoggerLevel(int loggerLevel) {
  +        setLoggerLevel(DEFAULT_CHANNEL, loggerLevel);
  +    }
  +    
  +    
  +    /**
        * Logger level getter.
        *
        * @return int logger level
        */
       public int getLoggerLevel() {
  +        return getLoggerLevel(DEFAULT_CHANNEL);
  +    }
  +    
  +    
  +    
  +    /**
  +     * Logger level getter.
  +     *
  +     * @return int logger level
  +     */
  +    public int getLoggerLevel(String channel) {
           return loggerLevel;
       }
       
  @@ -144,9 +165,9 @@
        * @param level The level used for logging.
        */
       public void log(Object data, String channel, int level) {
  -        if (loggerLevel >= level) {
  +        if (isEnabled(channel, level)) {
               String levelValue = "";
  -            if (channel.equals("default"))
  +            if (channel.equals(DEFAULT_CHANNEL))
                   channel = "";
               else
                   channel = channel + " - ";
  @@ -172,7 +193,7 @@
        * @param level The level used for logging.
        */
       public void log(Object data, int level) {
  -        this.log(data, "default", level);
  +        this.log(data, DEFAULT_CHANNEL, level);
       }
       
       
  @@ -182,8 +203,36 @@
        * @param data The object to log.
        */
       public void log(Object data) {
  -        this.log(data, "default", Logger.DEBUG);
  +        this.log(data, DEFAULT_CHANNEL, Logger.DEBUG);
  +    }
  +    
  +            
  +    
  +        
  +    
  +    /**
  +     * Check if the channel with the specified level is enabled for logging.
  +     * This implementation ignores the channel specification
  +     *
  +     * @param channel The channel specification
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(String channel, int level) {
  +        return getLoggerLevel() >= level;
       }
  +            
  +        
       
  +    /**
  +     * Check if the default channel with the specified level is enabled for logging.
  +     *
  +     * @param level   The level specification
  +     */
  +
  +    public boolean isEnabled(int level) {
  +        return isEnabled(DEFAULT_CHANNEL, level);
  +    }
  +            
       
   }