KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > wrapper > p6spy > P6SpyLogger


1 /**
2  * Copyright (C) 2001-2003 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.util.monolog.wrapper.p6spy;
19
20 import com.p6spy.engine.logging.appender.P6Logger;
21 import com.p6spy.engine.logging.appender.FormattedLogger;
22 import org.objectweb.util.monolog.api.Logger;
23 import org.objectweb.util.monolog.api.BasicLevel;
24
25 /**
26  * This class is a wrapper between the P6spy loggiing module and monolog. The
27  * aim is to log the SQL queries into a monolog loggger.
28  * @author S.Chassande-Barrioz
29  */

30 public class P6SpyLogger
31         extends FormattedLogger
32         implements P6Logger {
33
34     public static int level;
35     public static Logger logger;
36
37     public P6SpyLogger() {
38         level = BasicLevel.DEBUG;
39     }
40
41     // IMPLEMENTATION OF THE FormattedLogger INTERFACE //
42
//-------------------------------------------------//
43

44     public void logText(String JavaDoc s) {
45         if (logger == null) {
46             System.out.println(s);
47         } else if (logger.isLoggable(level)) {
48             logger.log(level, s);
49         }
50     }
51
52
53     // IMPLEMENTATION OF THE P6Logger INTERFACE //
54
//------------------------------------------//
55

56     public void logException(Exception JavaDoc e) {
57         if (logger == null) {
58             e.printStackTrace(System.out);
59         } else if (logger.isLoggable(level)) {
60             logger.log(level, e.getMessage(), e);
61         }
62     }
63 }
64
Popular Tags