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       *
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 CharSequence.
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 CharSequence 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       * @param t A Throwable.
88       * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise.
89       */
90      @Override
91      public boolean isEnabled(final Level level, final Marker marker, final Object message, final Throwable t) {
92          return logger.isEnabled(level, marker, message, t);
93      }
94  
95      /**
96       * Detect if the event would be logged.
97       *
98       * @param level The logging Level to check.
99       * @param marker A Marker or null.
100      * @param message The message.
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) {
105         return logger.isEnabled(level, marker, message);
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 params The parameters.
115      * @return true if the event would be logged for the Level, Marker, message and parameter.
116      */
117     @Override
118     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object... params) {
119         return logger.isEnabled(level, marker, message, params);
120     }
121 
122     @Override
123     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
124         return logger.isEnabled(level, marker, message, p0);
125     }
126 
127     @Override
128     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
129             final Object p1) {
130         return logger.isEnabled(level, marker, message, p0, p1);
131     }
132 
133     @Override
134     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
135             final Object p1, final Object p2) {
136         return logger.isEnabled(level, marker, message, p0, p1, p2);
137     }
138 
139     @Override
140     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
141             final Object p1, final Object p2, final Object p3) {
142         return logger.isEnabled(level, marker, message, p0, p1, p2, p3);
143     }
144 
145     @Override
146     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
147             final Object p1, final Object p2, final Object p3,
148             final Object p4) {
149         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4);
150     }
151 
152     @Override
153     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
154             final Object p1, final Object p2, final Object p3,
155             final Object p4, final Object p5) {
156         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5);
157     }
158 
159     @Override
160     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
161             final Object p1, final Object p2, final Object p3,
162             final Object p4, final Object p5, final Object p6) {
163         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6);
164     }
165 
166     @Override
167     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
168             final Object p1, final Object p2, final Object p3,
169             final Object p4, final Object p5, final Object p6,
170             final Object p7) {
171         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7);
172     }
173 
174     @Override
175     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
176             final Object p1, final Object p2, final Object p3,
177             final Object p4, final Object p5, final Object p6,
178             final Object p7, final Object p8) {
179         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, p8);
180     }
181 
182     @Override
183     public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0,
184             final Object p1, final Object p2, final Object p3,
185             final Object p4, final Object p5, final Object p6,
186             final Object p7, final Object p8, final Object p9) {
187         return logger.isEnabled(level, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
188     }
189 
190     /**
191      * Detect if the event would be logged.
192      *
193      * @param level The logging Level to check.
194      * @param marker A Marker or null.
195      * @param message The message.
196      * @param t A Throwable.
197      * @return true if the event would be logged for the Level, Marker, message and Throwable, false otherwise.
198      */
199     @Override
200     public boolean isEnabled(final Level level, final Marker marker, final String message, final Throwable t) {
201         return logger.isEnabled(level, marker, message, t);
202     }
203 
204     /**
205      * Always log an event. This tends to be already guarded by an enabled check, so this method should not check for
206      * the logger level again
207      *
208      * @param fqcn The fully qualified class name of the <b>caller</b>
209      * @param level The logging level
210      * @param marker The Marker
211      * @param message The Message.
212      * @param t A Throwable or null.
213      */
214     @Override
215     public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message,
216             final Throwable t) {
217         logger.logMessage(fqcn, level, marker, message, t);
218     }
219 }