KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > log > console > ConsoleLogger


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.log.console;
19
20 import org.sape.carbon.core.util.classify.SeverityEnum;
21 import org.sape.carbon.core.exception.ExceptionUtility;
22
23 import org.apache.commons.logging.Log;
24
25 /**
26  *
27  * Copyright 2003 Sapient
28  * @since carbon 2.0
29  * @author Anand Raman, March 2003
30  * @version $Revision: 1.7 $($Author: ghinkl $ / $Date: 2003/07/15 16:18:49 $)
31  */

32 public class ConsoleLogger implements Log {
33
34     /**
35      * Reference to the view shared by all <code>ConsoleLogger</code>
36      */

37     private static LogView console = null;
38
39     /**
40      * Name of the class associated with this logger
41      */

42     private String JavaDoc className = null;
43
44     static {
45         ConsoleLogger.console = new LogView();
46     }
47
48     /**
49      * Constructor
50      * @param name The class name with which this logger is associated
51      */

52     public ConsoleLogger(String JavaDoc name) {
53         this.className = name;
54     }
55
56     /**
57      * @see org.apache.commons.logging.Log#debug(Object)
58      */

59     public void debug(Object JavaDoc message) {
60         this.enqueueMessage(className, SeverityEnum.DEBUG, message);
61     }
62
63
64     /**
65      * @see org.apache.commons.logging.Log#error(Object)
66      */

67     public void error(Object JavaDoc message) {
68         this.enqueueMessage(className, SeverityEnum.ERROR, message);
69     }
70
71
72     /**
73      * @see org.apache.commons.logging.Log#fatal(Object)
74      */

75     public void fatal(Object JavaDoc message) {
76         this.enqueueMessage(className, SeverityEnum.FATAL, message);
77     }
78
79     /**
80      * @see org.apache.commons.logging.Log#info(Object)
81      */

82     public void info(Object JavaDoc message) {
83         this.enqueueMessage(className, SeverityEnum.INFO, message);
84     }
85
86     /**
87      * @see org.apache.commons.logging.Log#trace(Object)
88      */

89     public void trace(Object JavaDoc message) {
90         this.enqueueMessage(className, SeverityEnum.TRACE, message);
91     }
92
93     /**
94      * @see org.apache.commons.logging.Log#warn(Object)
95      */

96     public void warn(Object JavaDoc message) {
97         this.enqueueMessage(className, SeverityEnum.WARN, message);
98     }
99
100     protected void enqueueMessage(String JavaDoc sourceClass, SeverityEnum severity,
101                                                                Object JavaDoc message) {
102        ConsoleLogger.console.addMessage( sourceClass, severity, message);
103     }
104
105     /**
106      * @see org.apache.commons.logging.Log#isDebugEnabled()
107      */

108     public boolean isDebugEnabled() {
109         return isLogging();
110     }
111
112     /**
113      * @see org.apache.commons.logging.Log#isErrorEnabled()
114      */

115     public boolean isErrorEnabled() {
116         return isLogging();
117     }
118
119     /**
120      * @see org.apache.commons.logging.Log#isFatalEnabled()
121      */

122     public boolean isFatalEnabled() {
123         return isLogging();
124     }
125
126     /**
127      * @see org.apache.commons.logging.Log#isInfoEnabled()
128      */

129     public boolean isInfoEnabled() {
130         return isLogging();
131     }
132
133     /**
134      * @see org.apache.commons.logging.Log#isTraceEnabled()
135      */

136     public boolean isTraceEnabled() {
137         return isLogging();
138     }
139
140     /**
141      * @see org.apache.commons.logging.Log#isWarnEnabled()
142      */

143     public boolean isWarnEnabled() {
144         return isLogging();
145     }
146
147     /**
148      * This logger logs messages at all severities
149      */

150     protected boolean isLogging() {
151         return true;
152     }
153
154     /**
155      * @see org.apache.commons.logging.Log#debug(Object, Throwable)
156      */

157     public void debug(Object JavaDoc message, Throwable JavaDoc exception) {
158         debug(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
159     }
160
161     /**
162      * @see org.apache.commons.logging.Log#error(Object, Throwable)
163      */

164     public void error(Object JavaDoc message, Throwable JavaDoc exception) {
165         error(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
166     }
167
168     /**
169      * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
170      */

171     public void fatal(Object JavaDoc message, Throwable JavaDoc exception) {
172         fatal(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
173     }
174
175     /**
176      * @see org.apache.commons.logging.Log#info(Object, Throwable)
177      */

178     public void info(Object JavaDoc message, Throwable JavaDoc exception) {
179         info(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
180     }
181
182     /**
183      * @see org.apache.commons.logging.Log#trace(Object, Throwable)
184      */

185     public void trace(Object JavaDoc message, Throwable JavaDoc exception) {
186         trace(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
187     }
188
189     /**
190      * @see org.apache.commons.logging.Log#warn(Object, Throwable)
191      */

192     public void warn(Object JavaDoc message, Throwable JavaDoc exception) {
193         warn(message + "\nException: " + ExceptionUtility.printStackTracesToString(exception));
194     }
195
196 }
197
Popular Tags