001: /*
002: Copyright (C) 2002-2004 MySQL AB
003:
004: This program is free software; you can redistribute it and/or modify
005: it under the terms of version 2 of the GNU General Public License as
006: published by the Free Software Foundation.
007:
008: There are special exceptions to the terms and conditions of the GPL
009: as it is applied to this software. View the full text of the
010: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
011: software distribution.
012:
013: This program is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with this program; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021:
022:
023:
024: */
025: package com.mysql.jdbc.log;
026:
027: import org.apache.log4j.Level;
028: import org.apache.log4j.Logger;
029:
030: /**
031: * Implementation of log interface for Apache Log4j
032: *
033: * @author Mark Matthews
034: *
035: * @version $Id: Log4JLogger.java 3726 2005-05-19 15:52:24Z mmatthews $
036: */
037: public class Log4JLogger implements Log {
038:
039: private Logger logger;
040:
041: public Log4JLogger(String instanceName) {
042: this .logger = Logger.getLogger(instanceName);
043: }
044:
045: /*
046: * (non-Javadoc)
047: *
048: * @see com.mysql.jdbc.log.Log#isDebugEnabled()
049: */
050: public boolean isDebugEnabled() {
051: return this .logger.isDebugEnabled();
052: }
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see com.mysql.jdbc.log.Log#isErrorEnabled()
058: */
059: public boolean isErrorEnabled() {
060: return this .logger.isEnabledFor(Level.ERROR);
061: }
062:
063: /*
064: * (non-Javadoc)
065: *
066: * @see com.mysql.jdbc.log.Log#isFatalEnabled()
067: */
068: public boolean isFatalEnabled() {
069: return this .logger.isEnabledFor(Level.FATAL);
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see com.mysql.jdbc.log.Log#isInfoEnabled()
076: */
077: public boolean isInfoEnabled() {
078: return this .logger.isInfoEnabled();
079: }
080:
081: /*
082: * (non-Javadoc)
083: *
084: * @see com.mysql.jdbc.log.Log#isTraceEnabled()
085: */
086: public boolean isTraceEnabled() {
087: return this .logger.isDebugEnabled();
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see com.mysql.jdbc.log.Log#isWarnEnabled()
094: */
095: public boolean isWarnEnabled() {
096: return this .logger.isEnabledFor(Level.WARN);
097: }
098:
099: /*
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
106: .expandProfilerEventIfNecessary(LogUtils
107: .expandProfilerEventIfNecessary(msg)));
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see com.mysql.jdbc.log.Log#logDebug(java.lang.Object,
114: * java.lang.Throwable)
115: */
116: public void logDebug(Object msg, Throwable thrown) {
117: this .logger.debug(LogUtils.expandProfilerEventIfNecessary(msg),
118: thrown);
119: }
120:
121: /*
122: * (non-Javadoc)
123: *
124: * @see com.mysql.jdbc.log.Log#logError(java.lang.Object)
125: */
126: public void logError(Object msg) {
127: this .logger.error(LogUtils.expandProfilerEventIfNecessary(msg));
128: }
129:
130: /*
131: * (non-Javadoc)
132: *
133: * @see com.mysql.jdbc.log.Log#logError(java.lang.Object,
134: * java.lang.Throwable)
135: */
136: public void logError(Object msg, Throwable thrown) {
137: this .logger.error(LogUtils.expandProfilerEventIfNecessary(msg),
138: thrown);
139: }
140:
141: /*
142: * (non-Javadoc)
143: *
144: * @see com.mysql.jdbc.log.Log#logFatal(java.lang.Object)
145: */
146: public void logFatal(Object msg) {
147: this .logger.fatal(LogUtils.expandProfilerEventIfNecessary(msg));
148: }
149:
150: /*
151: * (non-Javadoc)
152: *
153: * @see com.mysql.jdbc.log.Log#logFatal(java.lang.Object,
154: * java.lang.Throwable)
155: */
156: public void logFatal(Object msg, Throwable thrown) {
157: this .logger.fatal(LogUtils.expandProfilerEventIfNecessary(msg),
158: thrown);
159: }
160:
161: /*
162: * (non-Javadoc)
163: *
164: * @see com.mysql.jdbc.log.Log#logInfo(java.lang.Object)
165: */
166: public void logInfo(Object msg) {
167: this .logger.info(LogUtils.expandProfilerEventIfNecessary(msg));
168: }
169:
170: /*
171: * (non-Javadoc)
172: *
173: * @see com.mysql.jdbc.log.Log#logInfo(java.lang.Object,
174: * java.lang.Throwable)
175: */
176: public void logInfo(Object msg, Throwable thrown) {
177: this .logger.info(LogUtils.expandProfilerEventIfNecessary(msg),
178: thrown);
179: }
180:
181: /*
182: * (non-Javadoc)
183: *
184: * @see com.mysql.jdbc.log.Log#logTrace(java.lang.Object)
185: */
186: public void logTrace(Object msg) {
187: this .logger.debug(LogUtils.expandProfilerEventIfNecessary(msg));
188: }
189:
190: /*
191: * (non-Javadoc)
192: *
193: * @see com.mysql.jdbc.log.Log#logTrace(java.lang.Object,
194: * java.lang.Throwable)
195: */
196: public void logTrace(Object msg, Throwable thrown) {
197: this .logger.debug(LogUtils.expandProfilerEventIfNecessary(msg),
198: thrown);
199: }
200:
201: /*
202: * (non-Javadoc)
203: *
204: * @see com.mysql.jdbc.log.Log#logWarn(java.lang.Object)
205: */
206: public void logWarn(Object msg) {
207: this .logger.warn(LogUtils.expandProfilerEventIfNecessary(msg));
208: }
209:
210: /*
211: * (non-Javadoc)
212: *
213: * @see com.mysql.jdbc.log.Log#logWarn(java.lang.Object,
214: * java.lang.Throwable)
215: */
216: public void logWarn(Object msg, Throwable thrown) {
217: this.logger.warn(LogUtils.expandProfilerEventIfNecessary(msg),
218: thrown);
219: }
220: }
|