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  
23  /**
24   * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers.
25   */
26  public class AbstractLoggerWrapper extends AbstractLogger {
27  
28      /**
29       * The wrapped Logger.
30       */
31      protected final AbstractLogger logger;
32  
33      /**
34       * Constructor that wraps and existing Logger.
35       * @param logger The Logger to wrap.
36       * @param name The name of the Logger.
37       */
38      public AbstractLoggerWrapper(AbstractLogger logger, String name) {
39          super(name);
40          this.logger = logger;
41      }
42  
43      /**
44       * Log an event.
45       * @param marker The Marker
46       * @param fqcn   The fully qualified class name of the <b>caller</b>
47       * @param level  The logging level
48       * @param data   The Message.
49       * @param t      A Throwable or null.
50       */
51      @Override
52      public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) {
53          logger.log(marker, fqcn, level, data, t);
54      }
55  
56      /**
57       * Detect if the event would be logged.
58       * @param level The logging Level to check.
59       * @param marker A Marker or null.
60       * @param data The message.
61       * @return true if the event would be logged for the Level, Marker and data, false otherwise.
62       */
63      @Override
64      public boolean isEnabled(Level level, Marker marker, String data) {
65          return logger.isEnabled(level, marker, data);
66      }
67  
68      /**
69       * Detect if the event would be logged.
70       * @param level The logging Level to check.
71       * @param marker A Marker or null.
72       * @param data The message.
73       * @param t A Throwable.
74       * @return true if the event would be logged for the Level, Marker, data and Throwable, false otherwise.
75       */
76      @Override
77      public boolean isEnabled(Level level, Marker marker, String data, Throwable t) {
78          return logger.isEnabled(level, marker, data, t);
79      }
80  
81      /**
82       * Detect if the event would be logged.
83       * @param level The logging Level to check.
84       * @param marker A Marker or null.
85       * @param data The message.
86       * @param p1 The parameters.
87       * @return true if the event would be logged for the Level, Marker, data and parameter.
88       */
89      @Override
90      public boolean isEnabled(Level level, Marker marker, String data, Object... p1) {
91          return logger.isEnabled(level, marker, data, p1);
92      }
93  
94      /**
95       * Detect if the event would be logged.
96       * @param level The logging Level to check.
97       * @param marker A Marker or null.
98       * @param data The message.
99       * @param t A Throwable.
100      * @return true if the event would be logged for the Level, Marker, Object and Throwable, false otherwise.
101      */
102     @Override
103     public boolean isEnabled(Level level, Marker marker, Object data, Throwable t) {
104         return logger.isEnabled(level, marker, data, t);
105     }
106 
107     /**
108      * Detect if the event would be logged.
109      * @param level The logging Level to check.
110      * @param marker A Marker or null.
111      * @param data The Message.
112      * @param t A Throwable.
113      * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise.
114      */
115     @Override
116     public boolean isEnabled(Level level, Marker marker, Message data, Throwable t) {
117         return logger.isEnabled(level, marker, data, t);
118     }
119 }