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; 023import org.apache.logging.log4j.util.StackLocatorUtil; 024 025/** 026 * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers. 027 */ 028public class ExtendedLoggerWrapper extends AbstractLogger { 029 030 private static final long serialVersionUID = 1L; 031 032 /** 033 * The wrapped Logger. 034 */ 035 protected final ExtendedLogger logger; 036 037 /** 038 * Constructor that wraps and existing Logger. 039 * 040 * @param logger The Logger to wrap. 041 * @param name The name of the Logger. 042 * @param messageFactory TODO 043 */ 044 public ExtendedLoggerWrapper(final ExtendedLogger logger, final String name, final MessageFactory messageFactory) { 045 super(name, messageFactory); 046 this.logger = logger; 047 } 048 049 @Override 050 public Level getLevel() { 051 return logger.getLevel(); 052 } 053 054 /** 055 * Detect if the event would be logged. 056 * 057 * @param level The logging Level to check. 058 * @param marker A Marker or null. 059 * @param message The Message. 060 * @param t A Throwable. 061 * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise. 062 */ 063 @Override 064 public boolean isEnabled(final Level level, final Marker marker, final Message message, final Throwable t) { 065 return logger.isEnabled(level, marker, message, t); 066 } 067 068 /** 069 * Detect if the event would be logged. 070 * 071 * @param level The logging Level to check. 072 * @param marker A Marker or null. 073 * @param message The message CharSequence. 074 * @param t A Throwable. 075 * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise. 076 */ 077 @Override 078 public boolean isEnabled(final Level level, final Marker marker, final CharSequence message, final Throwable t) { 079 return logger.isEnabled(level, marker, message, t); 080 } 081 082 /** 083 * Detect if the event would be logged. 084 * 085 * @param level The logging Level to check. 086 * @param marker A Marker or null. 087 * @param message The message. 088 * @param t A Throwable. 089 * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise. 090 */ 091 @Override 092 public boolean isEnabled(final Level level, final Marker marker, final Object message, final Throwable t) { 093 return logger.isEnabled(level, marker, message, t); 094 } 095 096 /** 097 * Detect if the event would be logged. 098 * 099 * @param level The logging Level to check. 100 * @param marker A Marker or null. 101 * @param message The message. 102 * @return true if the event would be logged for the Level, Marker, message and parameter. 103 */ 104 @Override 105 public boolean isEnabled(final Level level, final Marker marker, final String message) { 106 return logger.isEnabled(level, marker, message); 107 } 108 109 /** 110 * Detect if the event would be logged. 111 * 112 * @param level The logging Level to check. 113 * @param marker A Marker or null. 114 * @param message The message. 115 * @param params The parameters. 116 * @return true if the event would be logged for the Level, Marker, message and parameter. 117 */ 118 @Override 119 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object... params) { 120 return logger.isEnabled(level, marker, message, params); 121 } 122 123 @Override 124 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) { 125 return logger.isEnabled(level, marker, message, p0); 126 } 127 128 @Override 129 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 130 final Object p1) { 131 return logger.isEnabled(level, marker, message, p0, p1); 132 } 133 134 @Override 135 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 136 final Object p1, final Object p2) { 137 return logger.isEnabled(level, marker, message, p0, p1, p2); 138 } 139 140 @Override 141 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 142 final Object p1, final Object p2, final Object p3) { 143 return logger.isEnabled(level, marker, message, p0, p1, p2, p3); 144 } 145 146 @Override 147 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 148 final Object p1, final Object p2, final Object p3, 149 final Object p4) { 150 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4); 151 } 152 153 @Override 154 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 155 final Object p1, final Object p2, final Object p3, 156 final Object p4, final Object p5) { 157 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5); 158 } 159 160 @Override 161 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 162 final Object p1, final Object p2, final Object p3, 163 final Object p4, final Object p5, final Object p6) { 164 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6); 165 } 166 167 @Override 168 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 169 final Object p1, final Object p2, final Object p3, 170 final Object p4, final Object p5, final Object p6, 171 final Object p7) { 172 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7); 173 } 174 175 @Override 176 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 177 final Object p1, final Object p2, final Object p3, 178 final Object p4, final Object p5, final Object p6, 179 final Object p7, final Object p8) { 180 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, p8); 181 } 182 183 @Override 184 public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, 185 final Object p1, final Object p2, final Object p3, 186 final Object p4, final Object p5, final Object p6, 187 final Object p7, final Object p8, final Object p9) { 188 return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 189 } 190 191 /** 192 * Detect if the event would be logged. 193 * 194 * @param level The logging Level to check. 195 * @param marker A Marker or null. 196 * @param message The message. 197 * @param t A Throwable. 198 * @return true if the event would be logged for the Level, Marker, message and Throwable, false otherwise. 199 */ 200 @Override 201 public boolean isEnabled(final Level level, final Marker marker, final String message, final Throwable t) { 202 return logger.isEnabled(level, marker, message, t); 203 } 204 205 /** 206 * Always log an event. This tends to be already guarded by an enabled check, so this method should not check for 207 * the logger level again 208 * 209 * @param fqcn The fully qualified class name of the <b>caller</b> 210 * @param level The logging level 211 * @param marker The Marker 212 * @param message The Message. 213 * @param t A Throwable or null. 214 */ 215 @Override 216 public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, 217 final Throwable t) { 218 if (logger instanceof LocationAwareLogger && requiresLocation()) { 219 ((LocationAwareLogger) logger).logMessage(level, marker, fqcn, StackLocatorUtil.calcLocation(fqcn), 220 message, t); 221 } else { 222 logger.logMessage(fqcn, level, marker, message, t); 223 } 224 } 225}