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