KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > servlet > ServletXMLCLogger


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ServletXMLCLogger.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.servlet;
25
26 import java.io.PrintWriter JavaDoc;
27
28 import javax.servlet.ServletContext JavaDoc;
29
30 import org.enhydra.xml.xmlc.XMLCLogger;
31
32 /**
33  * XMLC logger interface to the Servlet logging API.
34  */

35 class ServletXMLCLogger implements XMLCLogger {
36     /**
37      * ServletContext this logger is associated with.
38      */

39     private ServletContext JavaDoc fServletContext;
40
41     /**
42      * Writer for XMLC informative logging.
43      */

44     private PrintWriter JavaDoc fInfoWriter;
45
46     /**
47      * Writer for XMLC debug logging.
48      */

49     private PrintWriter JavaDoc fDebugWriter;
50
51     /**
52      * Writer for XMLC error logging.
53      */

54     private PrintWriter JavaDoc fErrorWriter;
55
56     /**
57      * Constructor.
58      */

59     public ServletXMLCLogger(ServletContext JavaDoc servletContext,
60                              boolean enableInfoLogging,
61                              boolean enableDebugLogging) {
62         fServletContext = servletContext;
63
64         // Writer fields also serve as an indication if logging is enabled.
65
PrintWriter JavaDoc writer = new PrintWriter JavaDoc(new ServletLogWriter(fServletContext),
66                                              true);
67         if (enableInfoLogging) {
68             fInfoWriter = writer;
69         }
70         if (enableDebugLogging) {
71             fDebugWriter = writer;
72         }
73         fErrorWriter = writer;
74     }
75
76     /**
77      * Determine if info logging is enabled.
78      */

79     public boolean infoEnabled() {
80         return (fInfoWriter != null);
81     }
82
83     /**
84      * Get the info logging writer.
85      */

86     public PrintWriter JavaDoc getInfoWriter() {
87         return fInfoWriter;
88     }
89
90     /**
91      * Log an info message.
92      */

93     public void logInfo(String JavaDoc msg) {
94         if (fInfoWriter != null) {
95             fServletContext.log(msg);
96         }
97     }
98
99     /**
100      * Log an info message with exception.
101      */

102     public void logInfo(String JavaDoc msg,
103                         Throwable JavaDoc except) {
104         if (fInfoWriter != null) {
105             fServletContext.log(msg, except);
106         }
107     }
108
109     /**
110      * Determine if error logging is enabled.
111      */

112     public boolean errorEnabled() {
113         return (fErrorWriter != null);
114     }
115
116     /**
117      * Get the error logging writer.
118      */

119     public PrintWriter JavaDoc getErrorWriter() {
120         return fErrorWriter;
121     }
122
123     /**
124      * Log an error message.
125      */

126     public void logError(String JavaDoc msg) {
127         if (fErrorWriter != null) {
128             fServletContext.log(msg);
129         }
130     }
131
132     /**
133      * Log an error message with exception.
134      */

135     public void logError(String JavaDoc msg,
136                          Throwable JavaDoc except) {
137         if (fErrorWriter != null) {
138             fServletContext.log(msg, except);
139         }
140     }
141
142     /**
143      * Determine if debug logging is enabled.
144      */

145     public boolean debugEnabled() {
146         return (fDebugWriter != null);
147     }
148
149     /**
150      * Get the debug logging writer.
151      */

152     public PrintWriter JavaDoc getDebugWriter() {
153         return fDebugWriter;
154     }
155
156     /**
157      * Log a debug message.
158      */

159     public void logDebug(String JavaDoc msg) {
160         if (fDebugWriter != null) {
161             fServletContext.log(msg);
162         }
163     }
164
165     /**
166      * Log a debug message with exception.
167      */

168     public void logDebug(String JavaDoc msg,
169                          Throwable JavaDoc except) {
170         if (fDebugWriter != null) {
171             fServletContext.log(msg, except);
172         }
173     }
174 }
175
Popular Tags