Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.log » [javadoc | source]

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.kernel.log;
   19   
   20   import java.util.logging.ConsoleHandler;
   21   import java.util.logging.Handler;
   22   import java.util.logging.Level;
   23   import java.util.logging.Logger;
   24   
   25   import org.apache.commons.logging.Log;
   26   
   27   /**
   28    * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
   29    */
   30   public class BootstrapJdk14Log implements Log {
   31       static {
   32           Logger root = Logger.getLogger("");
   33   
   34           GeronimoLogging geronimoLevel = GeronimoLogging.getDefaultLevel();
   35           Level javaLevel;
   36           if (geronimoLevel == GeronimoLogging.TRACE) {
   37               javaLevel = Level.FINEST;
   38           } else if (geronimoLevel == GeronimoLogging.DEBUG) {
   39               javaLevel = Level.FINE;
   40           } else if (geronimoLevel == GeronimoLogging.INFO) {
   41               javaLevel = Level.INFO;
   42           } else if (geronimoLevel == GeronimoLogging.WARN) {
   43               javaLevel = Level.WARNING;
   44           } else {
   45               javaLevel = Level.SEVERE;
   46           }
   47   
   48           // set the root level
   49           root.setLevel(javaLevel);
   50   
   51           // set the console handler level (if present)
   52           Handler[] handlers = root.getHandlers();
   53           for (int index = 0; index < handlers.length; index++) {
   54               if (handlers[index] instanceof ConsoleHandler) {
   55                   handlers[index].setLevel(javaLevel);
   56               }
   57           }
   58       }
   59   
   60       private Logger logger = null;
   61   
   62       public BootstrapJdk14Log(String name) {
   63           logger = Logger.getLogger(name);
   64       }
   65   
   66       private void log(Level level, String messge, Throwable throwable) {
   67           if (logger.isLoggable(level)) {
   68               // need to determine if caller class name and method
   69               StackTraceElement locations[] = new Throwable().getStackTrace();
   70   
   71               // Caller will be the forth element
   72               String cname = "unknown";
   73               String method = "unknown";
   74               if (locations != null && locations.length > 3) {
   75                   StackTraceElement caller = locations[3];
   76                   cname = caller.getClassName();
   77                   method = caller.getMethodName();
   78               }
   79               if (throwable == null) {
   80                   logger.logp(level, cname, method, messge);
   81               } else {
   82                   logger.logp(level, cname, method, messge, throwable);
   83               }
   84           }
   85       }
   86   
   87       public void debug(Object message) {
   88           log(Level.FINE, String.valueOf(message), null);
   89       }
   90   
   91       public void debug(Object message, Throwable exception) {
   92           log(Level.FINE, String.valueOf(message), exception);
   93       }
   94   
   95       public void error(Object message) {
   96           log(Level.SEVERE, String.valueOf(message), null);
   97       }
   98   
   99       public void error(Object message, Throwable exception) {
  100           log(Level.SEVERE, String.valueOf(message), exception);
  101       }
  102   
  103       public void fatal(Object message) {
  104           log(Level.SEVERE, String.valueOf(message), null);
  105       }
  106   
  107       public void fatal(Object message, Throwable exception) {
  108           log(Level.SEVERE, String.valueOf(message), exception);
  109       }
  110   
  111       public Logger getLogger() {
  112           return this.logger;
  113       }
  114   
  115       public void info(Object message) {
  116           log(Level.INFO, String.valueOf(message), null);
  117       }
  118   
  119       public void info(Object message, Throwable exception) {
  120           log(Level.INFO, String.valueOf(message), exception);
  121       }
  122   
  123       public boolean isDebugEnabled() {
  124           return (logger.isLoggable(Level.FINE));
  125       }
  126   
  127       public boolean isErrorEnabled() {
  128           return (logger.isLoggable(Level.SEVERE));
  129       }
  130   
  131       public boolean isFatalEnabled() {
  132           return (logger.isLoggable(Level.SEVERE));
  133       }
  134   
  135       public boolean isInfoEnabled() {
  136           return (logger.isLoggable(Level.INFO));
  137       }
  138   
  139       public boolean isTraceEnabled() {
  140           return (logger.isLoggable(Level.FINEST));
  141       }
  142   
  143       public boolean isWarnEnabled() {
  144           return (logger.isLoggable(Level.WARNING));
  145       }
  146   
  147       public void trace(Object message) {
  148           log(Level.FINEST, String.valueOf(message), null);
  149       }
  150   
  151       public void trace(Object message, Throwable exception) {
  152           log(Level.FINEST, String.valueOf(message), exception);
  153       }
  154   
  155       public void warn(Object message) {
  156           log(Level.WARNING, String.valueOf(message), null);
  157       }
  158   
  159       public void warn(Object message, Throwable exception) {
  160           log(Level.WARNING, String.valueOf(message), exception);
  161       }
  162   }

Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.log » [javadoc | source]