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     */
017    package org.apache.logging.log4j.spi;
018    
019    import org.apache.logging.log4j.Level;
020    import org.apache.logging.log4j.Marker;
021    import org.apache.logging.log4j.message.Message;
022    
023    /**
024     * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers.
025     */
026    public class AbstractLoggerWrapper extends AbstractLogger {
027    
028        /**
029         * The wrapped Logger.
030         */
031        protected final AbstractLogger logger;
032    
033        /**
034         * Constructor that wraps and existing Logger.
035         * @param logger The Logger to wrap.
036         * @param name The name of the Logger.
037         */
038        public AbstractLoggerWrapper(AbstractLogger logger, String name) {
039            super(name);
040            this.logger = logger;
041        }
042    
043        /**
044         * Log an event.
045         * @param marker The Marker
046         * @param fqcn   The fully qualified class name of the <b>caller</b>
047         * @param level  The logging level
048         * @param data   The Message.
049         * @param t      A Throwable or null.
050         */
051        @Override
052        public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) {
053            logger.log(marker, fqcn, level, data, t);
054        }
055    
056        /**
057         * Detect if the event would be logged.
058         * @param level The logging Level to check.
059         * @param marker A Marker or null.
060         * @param data The message.
061         * @return true if the event would be logged for the Level, Marker and data, false otherwise.
062         */
063        @Override
064        public boolean isEnabled(Level level, Marker marker, String data) {
065            return logger.isEnabled(level, marker, data);
066        }
067    
068        /**
069         * Detect if the event would be logged.
070         * @param level The logging Level to check.
071         * @param marker A Marker or null.
072         * @param data The message.
073         * @param t A Throwable.
074         * @return true if the event would be logged for the Level, Marker, data and Throwable, false otherwise.
075         */
076        @Override
077        public boolean isEnabled(Level level, Marker marker, String data, Throwable t) {
078            return logger.isEnabled(level, marker, data, t);
079        }
080    
081        /**
082         * Detect if the event would be logged.
083         * @param level The logging Level to check.
084         * @param marker A Marker or null.
085         * @param data The message.
086         * @param p1 The parameters.
087         * @return true if the event would be logged for the Level, Marker, data and parameter.
088         */
089        @Override
090        public boolean isEnabled(Level level, Marker marker, String data, Object... p1) {
091            return logger.isEnabled(level, marker, data, p1);
092        }
093    
094        /**
095         * Detect if the event would be logged.
096         * @param level The logging Level to check.
097         * @param marker A Marker or null.
098         * @param data The message.
099         * @param t A Throwable.
100         * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise.
101         */
102        @Override
103        public boolean isEnabled(Level level, Marker marker, Object data, Throwable t) {
104            return logger.isEnabled(level, marker, data, t);
105        }
106    
107        /**
108         * Detect if the event would be logged.
109         * @param level The logging Level to check.
110         * @param marker A Marker or null.
111         * @param data The Message.
112         * @param t A Throwable.
113         * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise.
114         */
115        @Override
116        public boolean isEnabled(Level level, Marker marker, Message data, Throwable t) {
117            return logger.isEnabled(level, marker, data, t);
118        }
119    }