1 package org.apache.fulcrum.testcontainer.avalon.logger;
2
3 import java.util.Objects;
4
5 import org.apache.avalon.framework.logger.Logger;
6 import org.apache.logging.log4j.Level;
7
8 /*
9 * Licensed to the Apache Software Foundation (ASF) under one or more
10 * contributor license agreements. See the NOTICE file distributed with
11 * this work for additional information regarding copyright ownership.
12 * The ASF licenses this file to You under the Apache License, Version 2.0
13 * (the "License"); you may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24
25
26 import org.apache.logging.log4j.LogManager;
27
28 /**
29 * A Log4J2 wrapper class for Logger.
30 *
31 * - supports only minimal logging mechanism, without suppliers or objects.
32 *
33 * Use org.apache.fulcrum.yaafi.framework.logger.Log4j2Logger instead.
34 *
35 * @author <a href="mailto:dev@turbine.apache.org">Turbine Development Team</a>
36 * @version $Id$
37 */
38 @Deprecated
39 public final class Log4J2Logger
40 implements Logger
41 {
42
43 //underlying implementation
44 private final org.apache.logging.log4j.Logger m_logger;
45
46 /**
47 * Create a logger that delegates to specified category.
48 *
49 * @param logImpl the category to delegate to
50 */
51 public Log4J2Logger( final org.apache.logging.log4j.Logger logImpl )
52 {
53 Objects.requireNonNull( logImpl, "Log4J2 logger must not be null" );
54 m_logger = logImpl;
55 }
56
57 /**
58 * Log a debug message.
59 *
60 * @param message the message
61 */
62 public final void debug( final String message )
63 {
64 m_logger.log( Level.DEBUG, message );
65 }
66
67 /**
68 * Log a debug message.
69 *
70 * @param message the message
71 * @param throwable the throwable
72 */
73 public final void debug( final String message, final Throwable throwable )
74 {
75 m_logger.log( Level.DEBUG, message, throwable );
76 }
77
78 /**
79 * Determine if messages of priority "debug" will be logged.
80 *
81 * @return true if "debug" messages will be logged
82 */
83 public final boolean isDebugEnabled()
84 {
85 return m_logger.isDebugEnabled();
86 }
87
88 /**
89 * Log a info message.
90 *
91 * @param message the message
92 */
93 public final void info( final String message )
94 {
95 m_logger.log( Level.INFO, message );
96 }
97
98 /**
99 * Log a info message.
100 *
101 * @param message the message
102 * @param throwable the throwable
103 */
104 public final void info( final String message, final Throwable throwable )
105 {
106 m_logger.log( Level.INFO, message, throwable );
107 }
108
109 /**
110 * Determine if messages of priority "info" will be logged.
111 *
112 * @return true if "info" messages will be logged
113 */
114 public final boolean isInfoEnabled()
115 {
116 return m_logger.isInfoEnabled();
117 }
118
119 /**
120 * Log a warn message.
121 *
122 * @param message the message
123 */
124 public final void warn( final String message )
125 {
126 m_logger.log( Level.WARN, message );
127 }
128
129 /**
130 * Log a warn message.
131 *
132 * @param message the message
133 * @param throwable the throwable
134 */
135 public final void warn( final String message, final Throwable throwable )
136 {
137 m_logger.log( Level.WARN, message, throwable );
138 }
139
140 /**
141 * Determine if messages of priority "warn" will be logged.
142 *
143 * @return true if "warn" messages will be logged
144 */
145 public final boolean isWarnEnabled()
146 {
147 return m_logger.isEnabled( Level.WARN );
148 }
149
150 /**
151 * Log a error message.
152 *
153 * @param message the message
154 */
155 public final void error( final String message )
156 {
157 m_logger.log( Level.ERROR, message );
158 }
159
160 /**
161 * Log a error message.
162 *
163 * @param message the message
164 * @param throwable the throwable
165 */
166 public final void error( final String message, final Throwable throwable )
167 {
168 m_logger.log( Level.ERROR, message, throwable );
169 }
170
171 /**
172 * Determine if messages of priority "error" will be logged.
173 *
174 * @return true if "error" messages will be logged
175 */
176 public final boolean isErrorEnabled()
177 {
178 return m_logger.isEnabled( Level.ERROR );
179 }
180
181 /**
182 * Log a fatalError message.
183 *
184 * @param message the message
185 */
186 public final void fatalError( final String message )
187 {
188 m_logger.log( Level.FATAL, message );
189 }
190
191 /**
192 * Log a fatalError message.
193 *
194 * @param message the message
195 * @param throwable the throwable
196 */
197 public final void fatalError( final String message, final Throwable throwable )
198 {
199 m_logger.log( Level.ERROR, message, throwable );
200 }
201
202 /**
203 * Determine if messages of priority "fatalError" will be logged.
204 *
205 * @return true if "fatalError" messages will be logged
206 */
207 public final boolean isFatalErrorEnabled()
208 {
209 return m_logger.isEnabled( Level.FATAL );
210 }
211
212 /**
213 * Create a new child logger.
214 * The name of the child logger is [current-loggers-name].[passed-in-name]
215 * Throws <code>IllegalArgumentException</code> if name has an empty element name
216 *
217 * @param name the subname of this logger
218 * @return the new logger
219 */
220 public final Logger getChildLogger( final String name )
221 {
222 return new Log4J2Logger( LogManager.getLogger( m_logger.getName() + "." + name ) );
223 }
224 }