KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > util > CVSGrabLog


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  * See terms of license at gnu.org.
6  */

7
8 package net.sourceforge.cvsgrab.util;
9
10 import java.util.Date JavaDoc;
11
12 import org.apache.commons.logging.impl.SimpleLog;
13
14 /**
15  * Logs messages for CVSGrab.
16  *
17  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
18  * @version $Revision: 1.2 $ $Date: 2005/06/22 23:38:17 $
19  * @created on 3 fevr. 2004
20  */

21 public class CVSGrabLog extends SimpleLog {
22
23     /**
24      *
25      */

26     private static final long serialVersionUID = 8484066163771525005L;
27     private String JavaDoc prefix;
28     
29     /**
30      * Constructor for CVSGrabLog
31      * @param arg0
32      */

33     public CVSGrabLog(String JavaDoc arg0) {
34         super(arg0);
35     }
36
37     /**
38      * {@inheritDoc}
39      * @param type
40      * @param message
41      * @param t
42      */

43     protected void log(int type, Object JavaDoc message, Throwable JavaDoc t) {
44         // use a string buffer for better performance
45
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
46         
47         // append date-time if so configured
48
if(showDateTime) {
49             buf.append(dateFormatter.format(new Date JavaDoc()));
50             buf.append(" ");
51         }
52         
53         // append a readable representation of the log level
54
switch(type) {
55         case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
56         case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
57         case SimpleLog.LOG_LEVEL_INFO: break;
58         case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break;
59         case SimpleLog.LOG_LEVEL_ERROR: buf.append("[ERROR] "); break;
60         case SimpleLog.LOG_LEVEL_FATAL: buf.append("[FATAL] "); break;
61         }
62         
63         // append the name of the log instance if so configured
64
if( showShortName) {
65             if( prefix==null ) {
66                 // cut all but the last component of the name for both styles
67
prefix = logName.substring( logName.lastIndexOf(".") +1) + " - ";
68                 prefix = prefix.substring( prefix.lastIndexOf("/") +1) + "-";
69             }
70             buf.append( prefix );
71         } else if(showLogName) {
72             buf.append(String.valueOf(logName)).append(" - ");
73         }
74         
75         // append the message
76
buf.append(String.valueOf(message));
77         
78         // append stack trace if not null
79
if(t != null) {
80             buf.append(" <");
81             buf.append(t.toString());
82             buf.append(">");
83             
84             java.io.StringWriter JavaDoc sw= new java.io.StringWriter JavaDoc(1024);
85             java.io.PrintWriter JavaDoc pw= new java.io.PrintWriter JavaDoc(sw);
86             t.printStackTrace(pw);
87             pw.close();
88             buf.append(sw.toString());
89         }
90         
91         // print to System.err
92
System.err.println(buf.toString());
93     }
94
95 }
96
Popular Tags