01: /**
02: * Copyright (C) 2001-2003 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.util.monolog.wrapper.p6spy;
18:
19: import com.p6spy.engine.logging.appender.P6Logger;
20: import com.p6spy.engine.logging.appender.FormattedLogger;
21: import org.objectweb.util.monolog.api.Logger;
22: import org.objectweb.util.monolog.api.BasicLevel;
23:
24: /**
25: * This class is a wrapper between the P6spy loggiing module and monolog. The
26: * aim is to log the SQL queries into a monolog loggger.
27: * @author S.Chassande-Barrioz
28: */
29: public class P6SpyLogger extends FormattedLogger implements P6Logger {
30:
31: public static int level;
32: public static Logger logger;
33:
34: public P6SpyLogger() {
35: level = BasicLevel.DEBUG;
36: }
37:
38: // IMPLEMENTATION OF THE FormattedLogger INTERFACE //
39: //-------------------------------------------------//
40:
41: public void logText(String s) {
42: if (logger == null) {
43: System.out.println(s);
44: } else if (logger.isLoggable(level)) {
45: logger.log(level, s);
46: }
47: }
48:
49: // IMPLEMENTATION OF THE P6Logger INTERFACE //
50: //------------------------------------------//
51:
52: public void logException(Exception e) {
53: if (logger == null) {
54: e.printStackTrace(System.out);
55: } else if (logger.isLoggable(level)) {
56: logger.log(level, e.getMessage(), e);
57: }
58: }
59: }
|