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