001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.spi;
018
019import org.apache.logging.log4j.Level;
020import org.apache.logging.log4j.Marker;
021import org.apache.logging.log4j.message.Message;
022import org.apache.logging.log4j.message.MessageFactory;
023
024/**
025 * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers.
026 */
027public class AbstractLoggerWrapper extends AbstractLogger {
028
029    private static final long serialVersionUID = 1L;
030    
031    /**
032     * The wrapped Logger.
033     */
034    protected final AbstractLogger logger;
035
036    /**
037     * Constructor that wraps and existing Logger.
038     * @param logger The Logger to wrap.
039     * @param name The name of the Logger.
040     * @param messageFactory TODO
041     */
042    public AbstractLoggerWrapper(final AbstractLogger logger, final String name, final MessageFactory messageFactory) {
043        super(name, messageFactory);
044        this.logger = logger;
045    }
046
047    /**
048     * Detect if the event would be logged.
049     * @param level The logging Level to check.
050     * @param marker A Marker or null.
051     * @param data The Message.
052     * @param t A Throwable.
053     * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise.
054     */
055    @Override
056    public boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) {
057        return logger.isEnabled(level, marker, data, t);
058    }
059
060    /**
061     * Detect if the event would be logged.
062     * @param level The logging Level to check.
063     * @param marker A Marker or null.
064     * @param data The message.
065     * @param t A Throwable.
066     * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise.
067     */
068    @Override
069    public boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) {
070        return logger.isEnabled(level, marker, data, t);
071    }
072
073    /**
074     * Detect if the event would be logged.
075     * @param level The logging Level to check.
076     * @param marker A Marker or null.
077     * @param data The message.
078     * @return true if the event would be logged for the Level, Marker and data, false otherwise.
079     */
080    @Override
081    public boolean isEnabled(final Level level, final Marker marker, final String data) {
082        return logger.isEnabled(level, marker, data);
083    }
084
085    /**
086     * Detect if the event would be logged.
087     * @param level The logging Level to check.
088     * @param marker A Marker or null.
089     * @param data The message.
090     * @param p1 The parameters.
091     * @return true if the event would be logged for the Level, Marker, data and parameter.
092     */
093    @Override
094    public boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) {
095        return logger.isEnabled(level, marker, data, p1);
096    }
097
098    /**
099     * Detect if the event would be logged.
100     * @param level The logging Level to check.
101     * @param marker A Marker or null.
102     * @param data The message.
103     * @param t A Throwable.
104     * @return true if the event would be logged for the Level, Marker, data and Throwable, false otherwise.
105     */
106    @Override
107    public boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) {
108        return logger.isEnabled(level, marker, data, t);
109    }
110
111    /**
112     * Log an event.
113     * @param marker The Marker
114     * @param fqcn   The fully qualified class name of the <b>caller</b>
115     * @param level  The logging level
116     * @param data   The Message.
117     * @param t      A Throwable or null.
118     */
119    @Override
120    public void log(final Marker marker, final String fqcn, final Level level, final Message data, final Throwable t) {
121        logger.log(marker, fqcn, level, data, t);
122    }
123}