KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > log > CommonLogHandler


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27 package org.apache.tomcat.util.log;
28
29 import org.apache.tomcat.util.log.*;
30 import java.io.Writer JavaDoc;
31 import java.io.PrintWriter JavaDoc;
32 import java.io.FileWriter JavaDoc;
33 import java.io.File JavaDoc;
34 import java.io.OutputStreamWriter JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.io.StringWriter JavaDoc;
37
38 import java.util.*;
39
40 import com.sun.org.apache.commons.logging.*;
41
42 /**
43  * Log using common-logging.
44  *
45  * @author Costin Manolache
46  */

47 public class CommonLogHandler extends LogHandler {
48
49     private Hashtable loggers=new Hashtable();
50     
51     /**
52      * Prints log message and stack trace.
53      * This method should be overriden by real logger implementations
54      *
55      * @param prefix optional prefix.
56      * @param message the message to log.
57      * @param t the exception that was thrown.
58      * @param verbosityLevel what type of message is this?
59      * (WARNING/DEBUG/INFO etc)
60      */

61     public void log(String JavaDoc prefix, String JavaDoc msg, Throwable JavaDoc t,
62             int verbosityLevel)
63     {
64         if( prefix==null ) prefix="tomcat";
65
66         com.sun.org.apache.commons.logging.Log l=(com.sun.org.apache.commons.logging.Log)loggers.get( prefix );
67         if( l==null ) {
68             l=LogFactory.getLog( prefix );
69             loggers.put( prefix, l );
70         }
71         
72     if( verbosityLevel > this.level ) return;
73
74         if( t==null ) {
75             if( verbosityLevel == Log.FATAL )
76                 l.fatal(msg);
77             else if( verbosityLevel == Log.ERROR )
78                 l.error( msg );
79             else if( verbosityLevel == Log.WARNING )
80                 l.warn( msg );
81             else if( verbosityLevel == Log.INFORMATION)
82                 l.info( msg );
83             else if( verbosityLevel == Log.DEBUG )
84                 l.debug( msg );
85         } else {
86             if( verbosityLevel == Log.FATAL )
87                 l.fatal(msg, t);
88             else if( verbosityLevel == Log.ERROR )
89                 l.error( msg, t );
90             else if( verbosityLevel == Log.WARNING )
91                 l.warn( msg, t );
92             else if( verbosityLevel == Log.INFORMATION)
93                 l.info( msg, t );
94             else if( verbosityLevel == Log.DEBUG )
95                 l.debug( msg, t );
96         }
97     }
98
99     /**
100      * Flush the log.
101      */

102     public void flush() {
103     // Nothing - commons logging doesn't have the notion
104
}
105
106     /**
107      * Close the log.
108      */

109     public synchronized void close() {
110     // Nothing - commons logging doesn't have the notion
111
}
112     
113 }
114
Popular Tags