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