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 ExtendedLoggerWrapper extends AbstractLogger {
028
029    private static final long serialVersionUID = 1L;
030
031    /**
032     * The wrapped Logger.
033     */
034    protected final ExtendedLogger logger;
035
036    /**
037     * Constructor that wraps and existing Logger.
038     * 
039     * @param logger The Logger to wrap.
040     * @param name The name of the Logger.
041     * @param messageFactory TODO
042     */
043    public ExtendedLoggerWrapper(final ExtendedLogger logger, final String name, final MessageFactory messageFactory) {
044        super(name, messageFactory);
045        this.logger = logger;
046    }
047
048    @Override
049    public Level getLevel() {
050        return logger.getLevel();
051    }
052
053    /**
054     * Detect if the event would be logged.
055     * 
056     * @param level The logging Level to check.
057     * @param marker A Marker or null.
058     * @param message The Message.
059     * @param t A Throwable.
060     * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise.
061     */
062    @Override
063    public boolean isEnabled(final Level level, final Marker marker, final Message message, final Throwable t) {
064        return logger.isEnabled(level, marker, message, t);
065    }
066
067    /**
068     * Detect if the event would be logged.
069     * 
070     * @param level The logging Level to check.
071     * @param marker A Marker or null.
072     * @param message The message.
073     * @param t A Throwable.
074     * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise.
075     */
076    @Override
077    public boolean isEnabled(final Level level, final Marker marker, final Object message, final Throwable t) {
078        return logger.isEnabled(level, marker, message, t);
079    }
080
081    /**
082     * Detect if the event would be logged.
083     * 
084     * @param level The logging Level to check.
085     * @param marker A Marker or null.
086     * @param message The message.
087     * @return true if the event would be logged for the Level, Marker, message and parameter.
088     */
089    @Override
090    public boolean isEnabled(final Level level, final Marker marker, final String message) {
091        return logger.isEnabled(level, marker, message);
092    }
093
094    /**
095     * Detect if the event would be logged.
096     * 
097     * @param level The logging Level to check.
098     * @param marker A Marker or null.
099     * @param message The message.
100     * @param params The parameters.
101     * @return true if the event would be logged for the Level, Marker, message and parameter.
102     */
103    @Override
104    public boolean isEnabled(final Level level, final Marker marker, final String message, final Object... params) {
105        return logger.isEnabled(level, marker, message, params);
106    }
107
108    /**
109     * Detect if the event would be logged.
110     * 
111     * @param level The logging Level to check.
112     * @param marker A Marker or null.
113     * @param message The message.
114     * @param t A Throwable.
115     * @return true if the event would be logged for the Level, Marker, message and Throwable, false otherwise.
116     */
117    @Override
118    public boolean isEnabled(final Level level, final Marker marker, final String message, final Throwable t) {
119        return logger.isEnabled(level, marker, message, t);
120    }
121
122    /**
123     * Always log an event. This tends to be already guarded by an enabled check, so this method should not check for
124     * the logger level again
125     * 
126     * @param fqcn The fully qualified class name of the <b>caller</b>
127     * @param level The logging level
128     * @param marker The Marker
129     * @param message The Message.
130     * @param t A Throwable or null.
131     */
132    @Override
133    public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message,
134            final Throwable t) {
135        logger.logMessage(fqcn, level, marker, message, t);
136    }
137}