View Javadoc

    1   /*
    2    * Copyright 2009 Red Hat, Inc.
    3    *
    4    * Red Hat licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the
    6    * License.  You may obtain a copy of the License at:
    7    *
    8    *    http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    13   * License for the specific language governing permissions and limitations
    14   * under the License.
    15   */
    16  package org.jboss.netty.logging;
    17
    18  import java.util.logging.Level;
    19  import java.util.logging.Logger;
    20
    21  /**
    22   * <a href="http://java.sun.com/javase/6/docs/technotes/guides/logging/index.html">java.util.logging</a>
    23   * logger.
    24   *
    25   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    26   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    27   *
    28   * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
    29   *
    30   */
    31  class JdkLogger extends AbstractInternalLogger {
    32
    33      private final Logger logger;
    34      private final String loggerName;
    35
    36      JdkLogger(Logger logger, String loggerName) {
    37          this.logger = logger;
    38          this.loggerName = loggerName;
    39      }
    40
    41      public void debug(String msg) {
    42          logger.logp(Level.FINE, loggerName, null, msg);
    43      }
    44
    45      public void debug(String msg, Throwable cause) {
    46          logger.logp(Level.FINE, loggerName, null, msg, cause);
    47      }
    48
    49      public void error(String msg) {
    50          logger.logp(Level.SEVERE, loggerName, null, msg);
    51      }
    52
    53      public void error(String msg, Throwable cause) {
    54          logger.logp(Level.SEVERE, loggerName, null, msg, cause);
    55      }
    56
    57      public void info(String msg) {
    58          logger.logp(Level.INFO, loggerName, null, msg);
    59      }
    60
    61      public void info(String msg, Throwable cause) {
    62          logger.logp(Level.INFO, loggerName, null, msg, cause);
    63      }
    64
    65      public boolean isDebugEnabled() {
    66          return logger.isLoggable(Level.FINE);
    67      }
    68
    69      public boolean isErrorEnabled() {
    70          return logger.isLoggable(Level.SEVERE);
    71      }
    72
    73      public boolean isInfoEnabled() {
    74          return logger.isLoggable(Level.INFO);
    75      }
    76
    77      public boolean isWarnEnabled() {
    78          return logger.isLoggable(Level.WARNING);
    79      }
    80
    81      public void warn(String msg) {
    82          logger.logp(Level.WARNING, loggerName, null, msg);
    83      }
    84
    85      public void warn(String msg, Throwable cause) {
    86          logger.logp(Level.WARNING, loggerName, null, msg, cause);
    87      }
    88
    89      @Override
    90      public String toString() {
    91          return loggerName;
    92      }
    93  }