KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > logging > P6SpyLogger


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.logging;
20
21 import java.util.logging.Logger JavaDoc;
22
23 import com.p6spy.engine.logging.appender.FormattedLogger;
24 import com.p6spy.engine.logging.appender.P6Logger;
25
26 /**
27  * Appender for P6Spy SQL logger.
28  *
29  *
30  * @author Stefano Fornari @ Funambol.com
31  * @version $Id: P6SpyLogger.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
32  */

33 public class P6SpyLogger extends FormattedLogger implements P6Logger {
34     public static final String JavaDoc LOG_NAME = "sync4j.log.sql";
35     
36     protected Logger JavaDoc log = null;
37     
38     public P6SpyLogger() {
39         log = Logger.getLogger(LOG_NAME);
40     }
41     
42     public void logSQL(int connectionId,
43                        String JavaDoc now ,
44                        long elapsed ,
45                        String JavaDoc category ,
46                        String JavaDoc prepared ,
47                        String JavaDoc sql ) {
48                            
49         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50         
51         sb.append(now).append(' ');
52         sb.append((connectionId==-1 ? "" : String.valueOf(connectionId))).append(' ');
53         sb.append(category).append(' ');
54         
55         if ((prepared != null) && (prepared.length() >= 0)) {
56             logText(sb.toString() + prepared);
57         }
58         
59         sb.append(elapsed).append(' ');
60         sb.append(sql).append(' ');
61
62         logText(sb.toString());
63     }
64     
65     public void logText(String JavaDoc text) {
66         log.info(text);
67         setLastEntry(text);
68     }
69     
70     public void logException(Exception JavaDoc e) {
71         log.throwing("-", "-", e);
72     }
73 }
Popular Tags