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