KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > transaction > util > PrintWriterLogger


1 /*
2  * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//transaction/src/java/org/apache/commons/transaction/util/PrintWriterLogger.java,v 1.2 2004/12/16 23:32:44 ozeigermann Exp $
3 <<<<<<< .mine
4  * $Revision: 1.2 $
5  * $Date: 2005-02-26 14:16:14 +0100 (Sa, 26 Feb 2005) $
6 =======
7  * $Revision$
8  * $Date: 2005-02-26 14:16:14 +0100 (Sa, 26 Feb 2005) $
9 >>>>>>> .r168169
10  *
11  * ====================================================================
12  *
13  * Copyright 2004 The Apache Software Foundation
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  *
27  */

28
29 package org.apache.commons.transaction.util;
30
31 import java.io.PrintWriter JavaDoc;
32
33 /**
34  * Logger implementation that logs into a pring writer like the one
35  * passed in JCA.
36  *
37  * @version $Revision$
38  */

39 public class PrintWriterLogger implements LoggerFacade {
40
41     protected PrintWriter JavaDoc printWriter;
42     protected String JavaDoc name;
43     protected boolean debug;
44
45     public PrintWriterLogger(PrintWriter JavaDoc printWriter, String JavaDoc name, boolean debug) {
46         this.printWriter = printWriter;
47         this.name = name;
48         this.debug = debug;
49     }
50
51     public LoggerFacade createLogger(String JavaDoc newName) {
52         return new PrintWriterLogger(this.printWriter, newName, this.debug);
53     }
54
55     public void logInfo(String JavaDoc message) {
56         log("INFO", message);
57     }
58
59     public void logFine(String JavaDoc message) {
60         if (debug)
61         log("FINE", message);
62     }
63
64     public boolean isFineEnabled() {
65         return debug;
66     }
67
68     public void logFiner(String JavaDoc message) {
69         if (debug)
70             log("FINER", message);
71     }
72
73     public boolean isFinerEnabled() {
74         return debug;
75     }
76
77     public void logFinest(String JavaDoc message) {
78         if (debug)
79             log("FINEST", message);
80     }
81
82     public boolean isFinestEnabled() {
83         return debug;
84     }
85
86     public void logWarning(String JavaDoc message) {
87         log("WARNING", message);
88     }
89
90     public void logWarning(String JavaDoc message, Throwable JavaDoc t) {
91         log("WARNING", message);
92         t.printStackTrace(printWriter);
93     }
94
95     public void logSevere(String JavaDoc message) {
96         log("SEVERE", message);
97     }
98
99     public void logSevere(String JavaDoc message, Throwable JavaDoc t) {
100         log("SEVERE", message);
101         t.printStackTrace(printWriter);
102     }
103
104     protected void log(String JavaDoc level, String JavaDoc message) {
105         printWriter.write(name + "(" + level + ":" + message);
106         printWriter.flush();
107     }
108 }
109
Popular Tags