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