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.spi; 18 19 import org.apache.logging.log4j.Level; 20 import org.apache.logging.log4j.Marker; 21 import org.apache.logging.log4j.message.Message; 22 import org.apache.logging.log4j.message.MessageFactory; 23 24 /** 25 * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers. 26 */ 27 public class AbstractLoggerWrapper extends AbstractLogger { 28 29 private static final long serialVersionUID = 1L; 30 31 /** 32 * The wrapped Logger. 33 */ 34 protected final AbstractLogger logger; 35 36 /** 37 * Constructor that wraps and existing Logger. 38 * @param logger The Logger to wrap. 39 * @param name The name of the Logger. 40 * @param messageFactory TODO 41 */ 42 public AbstractLoggerWrapper(final AbstractLogger logger, final String name, final MessageFactory messageFactory) { 43 super(name, messageFactory); 44 this.logger = logger; 45 } 46 47 /** 48 * Detect if the event would be logged. 49 * @param level The logging Level to check. 50 * @param marker A Marker or null. 51 * @param data The Message. 52 * @param t A Throwable. 53 * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise. 54 */ 55 @Override 56 public boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) { 57 return logger.isEnabled(level, marker, data, t); 58 } 59 60 /** 61 * Detect if the event would be logged. 62 * @param level The logging Level to check. 63 * @param marker A Marker or null. 64 * @param data The message. 65 * @param t A Throwable. 66 * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise. 67 */ 68 @Override 69 public boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) { 70 return logger.isEnabled(level, marker, data, t); 71 } 72 73 /** 74 * Detect if the event would be logged. 75 * @param level The logging Level to check. 76 * @param marker A Marker or null. 77 * @param data The message. 78 * @return true if the event would be logged for the Level, Marker and data, false otherwise. 79 */ 80 @Override 81 public boolean isEnabled(final Level level, final Marker marker, final String data) { 82 return logger.isEnabled(level, marker, data); 83 } 84 85 /** 86 * Detect if the event would be logged. 87 * @param level The logging Level to check. 88 * @param marker A Marker or null. 89 * @param data The message. 90 * @param p1 The parameters. 91 * @return true if the event would be logged for the Level, Marker, data and parameter. 92 */ 93 @Override 94 public boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) { 95 return logger.isEnabled(level, marker, data, p1); 96 } 97 98 /** 99 * 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 }