1 | /* |
2 | Copyright (C) 2002-2004 MySQL AB |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of version 2 of the GNU General Public License as |
6 | published by the Free Software Foundation. |
7 | |
8 | There are special exceptions to the terms and conditions of the GPL |
9 | as it is applied to this software. View the full text of the |
10 | exception in file EXCEPTIONS-CONNECTOR-J in the directory of this |
11 | software distribution. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | |
22 | |
23 | |
24 | */ |
25 | package com.mysql.jdbc.log; |
26 | |
27 | import org.apache.log4j.Level; |
28 | import org.apache.log4j.Logger; |
29 | |
30 | /** |
31 | * Implementation of log interface for Apache Log4j |
32 | * |
33 | * @author Mark Matthews |
34 | * |
35 | * @version $Id: Log4JLogger.java 3726 2005-05-19 15:52:24Z mmatthews $ |
36 | */ |
37 | public class Log4JLogger implements Log { |
38 | |
39 | private Logger logger; |
40 | |
41 | public Log4JLogger(String instanceName) { |
42 | this.logger = Logger.getLogger(instanceName); |
43 | } |
44 | |
45 | /* |
46 | * (non-Javadoc) |
47 | * |
48 | * @see com.mysql.jdbc.log.Log#isDebugEnabled() |
49 | */ |
50 | public boolean isDebugEnabled() { |
51 | return this.logger.isDebugEnabled(); |
52 | } |
53 | |
54 | /* |
55 | * (non-Javadoc) |
56 | * |
57 | * @see com.mysql.jdbc.log.Log#isErrorEnabled() |
58 | */ |
59 | public boolean isErrorEnabled() { |
60 | return this.logger.isEnabledFor(Level.ERROR); |
61 | } |
62 | |
63 | /* |
64 | * (non-Javadoc) |
65 | * |
66 | * @see com.mysql.jdbc.log.Log#isFatalEnabled() |
67 | */ |
68 | public boolean isFatalEnabled() { |
69 | return this.logger.isEnabledFor(Level.FATAL); |
70 | } |
71 | |
72 | /* |
73 | * (non-Javadoc) |
74 | * |
75 | * @see com.mysql.jdbc.log.Log#isInfoEnabled() |
76 | */ |
77 | public boolean isInfoEnabled() { |
78 | return this.logger.isInfoEnabled(); |
79 | } |
80 | |
81 | /* |
82 | * (non-Javadoc) |
83 | * |
84 | * @see com.mysql.jdbc.log.Log#isTraceEnabled() |
85 | */ |
86 | public boolean isTraceEnabled() { |
87 | return this.logger.isDebugEnabled(); |
88 | } |
89 | |
90 | /* |
91 | * (non-Javadoc) |
92 | * |
93 | * @see com.mysql.jdbc.log.Log#isWarnEnabled() |
94 | */ |
95 | public boolean isWarnEnabled() { |
96 | return this.logger.isEnabledFor(Level.WARN); |
97 | } |
98 | |
99 | /* |
100 | * (non-Javadoc) |
101 | * |
102 | * @see com.mysql.jdbc.log.Log#logDebug(java.lang.Object) |
103 | */ |
104 | public void logDebug(Object msg) { |
105 | this.logger.debug(LogUtils.expandProfilerEventIfNecessary(LogUtils |
106 | .expandProfilerEventIfNecessary(msg))); |
107 | } |
108 | |
109 | /* |
110 | * (non-Javadoc) |
111 | * |
112 | * @see com.mysql.jdbc.log.Log#logDebug(java.lang.Object, |
113 | * java.lang.Throwable) |
114 | */ |
115 | public void logDebug(Object msg, Throwable thrown) { |
116 | this.logger.debug(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
117 | } |
118 | |
119 | /* |
120 | * (non-Javadoc) |
121 | * |
122 | * @see com.mysql.jdbc.log.Log#logError(java.lang.Object) |
123 | */ |
124 | public void logError(Object msg) { |
125 | this.logger.error(LogUtils.expandProfilerEventIfNecessary(msg)); |
126 | } |
127 | |
128 | /* |
129 | * (non-Javadoc) |
130 | * |
131 | * @see com.mysql.jdbc.log.Log#logError(java.lang.Object, |
132 | * java.lang.Throwable) |
133 | */ |
134 | public void logError(Object msg, Throwable thrown) { |
135 | this.logger.error(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
136 | } |
137 | |
138 | /* |
139 | * (non-Javadoc) |
140 | * |
141 | * @see com.mysql.jdbc.log.Log#logFatal(java.lang.Object) |
142 | */ |
143 | public void logFatal(Object msg) { |
144 | this.logger.fatal(LogUtils.expandProfilerEventIfNecessary(msg)); |
145 | } |
146 | |
147 | /* |
148 | * (non-Javadoc) |
149 | * |
150 | * @see com.mysql.jdbc.log.Log#logFatal(java.lang.Object, |
151 | * java.lang.Throwable) |
152 | */ |
153 | public void logFatal(Object msg, Throwable thrown) { |
154 | this.logger.fatal(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
155 | } |
156 | |
157 | /* |
158 | * (non-Javadoc) |
159 | * |
160 | * @see com.mysql.jdbc.log.Log#logInfo(java.lang.Object) |
161 | */ |
162 | public void logInfo(Object msg) { |
163 | this.logger.info(LogUtils.expandProfilerEventIfNecessary(msg)); |
164 | } |
165 | |
166 | /* |
167 | * (non-Javadoc) |
168 | * |
169 | * @see com.mysql.jdbc.log.Log#logInfo(java.lang.Object, |
170 | * java.lang.Throwable) |
171 | */ |
172 | public void logInfo(Object msg, Throwable thrown) { |
173 | this.logger.info(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
174 | } |
175 | |
176 | /* |
177 | * (non-Javadoc) |
178 | * |
179 | * @see com.mysql.jdbc.log.Log#logTrace(java.lang.Object) |
180 | */ |
181 | public void logTrace(Object msg) { |
182 | this.logger.debug(LogUtils.expandProfilerEventIfNecessary(msg)); |
183 | } |
184 | |
185 | /* |
186 | * (non-Javadoc) |
187 | * |
188 | * @see com.mysql.jdbc.log.Log#logTrace(java.lang.Object, |
189 | * java.lang.Throwable) |
190 | */ |
191 | public void logTrace(Object msg, Throwable thrown) { |
192 | this.logger.debug(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
193 | } |
194 | |
195 | /* |
196 | * (non-Javadoc) |
197 | * |
198 | * @see com.mysql.jdbc.log.Log#logWarn(java.lang.Object) |
199 | */ |
200 | public void logWarn(Object msg) { |
201 | this.logger.warn(LogUtils.expandProfilerEventIfNecessary(msg)); |
202 | } |
203 | |
204 | /* |
205 | * (non-Javadoc) |
206 | * |
207 | * @see com.mysql.jdbc.log.Log#logWarn(java.lang.Object, |
208 | * java.lang.Throwable) |
209 | */ |
210 | public void logWarn(Object msg, Throwable thrown) { |
211 | this.logger.warn(LogUtils.expandProfilerEventIfNecessary(msg), thrown); |
212 | } |
213 | } |