View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache license, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License. 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  package org.apache.logging.log4j.jcl;
    18
    19  import java.io.Serializable;
    20
    21  import org.apache.commons.logging.Log;
    22  import org.apache.logging.log4j.Level;
    23  import org.apache.logging.log4j.spi.ExtendedLogger;
    24
    25  /**
    26   *
    27   */
    28  public class Log4jLog implements Log, Serializable {
    29
    30      private static final long serialVersionUID = 1L;
    31      private static final String FQCN = Log4jLog.class.getName();
    32
    33      private final ExtendedLogger logger;
    34
    35      public Log4jLog(final ExtendedLogger logger) {
    36          this.logger = logger;
    37      }
    38
    39      @Override
    40      public boolean isDebugEnabled() {
    41          return logger.isEnabled(Level.DEBUG, null, null);
    42      }
    43
    44      @Override
    45      public boolean isErrorEnabled() {
    46          return logger.isEnabled(Level.ERROR, null, null);
    47      }
    48
    49      @Override
    50      public boolean isFatalEnabled() {
    51          return logger.isEnabled(Level.FATAL, null, null);
    52      }
    53
    54      @Override
    55      public boolean isInfoEnabled() {
    56          return logger.isEnabled(Level.INFO, null, null);
    57      }
    58
    59      @Override
    60      public boolean isTraceEnabled() {
    61          return logger.isEnabled(Level.TRACE, null, null);
    62      }
    63
    64      @Override
    65      public boolean isWarnEnabled() {
    66          return logger.isEnabled(Level.WARN, null, null);
    67      }
    68
    69      @Override
    70      public void trace(final Object message) {
    71          logger.logIfEnabled(FQCN, Level.TRACE, null, message, null);
    72      }
    73
    74      @Override
    75      public void trace(final Object message, final Throwable t) {
    76          logger.logIfEnabled(FQCN, Level.TRACE, null, message, t);
    77      }
    78
    79      @Override
    80      public void debug(final Object message) {
    81          logger.logIfEnabled(FQCN, Level.DEBUG, null, message, null);
    82      }
    83
    84      @Override
    85      public void debug(final Object message, final Throwable t) {
    86          logger.logIfEnabled(FQCN, Level.DEBUG, null, message, t);
    87      }
    88
    89      @Override
    90      public void info(final Object message) {
    91          logger.logIfEnabled(FQCN, Level.INFO, null, message, null);
    92      }
    93
    94      @Override
    95      public void info(final Object message, final Throwable t) {
    96          logger.logIfEnabled(FQCN, Level.INFO, null, message, t);
    97      }
    98
    99      @Override
    100     public void warn(final Object message) {
    101         logger.logIfEnabled(FQCN, Level.WARN, null, message, null);
    102     }
    103
    104     @Override
    105     public void warn(final Object message, final Throwable t) {
    106         logger.logIfEnabled(FQCN, Level.WARN, null, message, t);
    107     }
    108
    109     @Override
    110     public void error(final Object message) {
    111         logger.logIfEnabled(FQCN, Level.ERROR, null, message, null);
    112     }
    113
    114     @Override
    115     public void error(final Object message, final Throwable t) {
    116         logger.logIfEnabled(FQCN, Level.ERROR, null, message, t);
    117     }
    118
    119     @Override
    120     public void fatal(final Object message) {
    121         logger.logIfEnabled(FQCN, Level.FATAL, null, message, null);
    122     }
    123
    124     @Override
    125     public void fatal(final Object message, final Throwable t) {
    126         logger.logIfEnabled(FQCN, Level.FATAL, null, message, t);
    127     }
    128 }