1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.common.traps;
22
23 import org.apache.commons.logging.Log;
24
25 import autohit.common.AutohitLogInjectorWrapper;
26
27 /**
28 * Traps Commons logging. You must call the static method
29 * setTrap() at least once per JVM to get this working.
30 *
31 * @author Erich P. Gatejen
32 * @version 1.0
33 * <i>Version History</i>
34 * <code>EPG - Initial - 19Jul03</code>
35 *
36 */
37 public final class CommonsLoggerTrap implements Log {
38
39 /**
40 * Remember where out root logger is.
41 */
42 static private AutohitLogInjectorWrapper log;
43
44 /**
45 * Me
46 */
47 private String me;
48
49
50 /**
51 * Constructor
52 * @param name Name of the logger to be constructed
53 */
54 public CommonsLoggerTrap(String name) {
55 me = name;
56 }
57
58 /**
59 * Log a message with debug log level.
60 * @param logger a logger in which to dump everything.
61 */
62 public static void setTrap(AutohitLogInjectorWrapper logger) {
63 System.setProperty(
64 "org.apache.commons.logging.Log",
65 "autohit.common.traps.CommonsLoggerTrap");
66 log = logger;
67 }
68
69 /**
70 * Log a message with debug log level.
71 */
72 public void debug(Object message) {
73 //if (log.debugState())
74 // log.debug(me + " : " + String.valueOf(message));
75 }
76
77 /**
78 * Log a message and exception with debug log level.
79 */
80 public void debug(Object message, Throwable exception) {
81 //if (log.debugState())
82 // log.debug(me + " : " + String.valueOf(message) + " : " + exception.getMessage());
83 }
84
85 /**
86 * Log a message with error log level.
87 */
88 public void error(Object message) {
89 log.error(me + " : " + String.valueOf(message));
90 }
91
92 /**
93 * Log a message and exception with error log level.
94 */
95 public void error(Object message, Throwable exception) {
96 log.error(me + " : " + String.valueOf(message) + " : " + exception.getMessage());
97 }
98
99 /**
100 * Log a message with fatal log level.
101 */
102 public void fatal(Object message) {
103 log.error(me + " : " + String.valueOf(message));
104 }
105
106 /**
107 * Log a message and exception with fatal log level.
108 */
109 public void fatal(Object message, Throwable exception) {
110 log.error(me + " : " + String.valueOf(message) + " : " + exception.getMessage());
111 }
112
113 /**
114 * Log a message with info log level.
115 */
116 public void info(Object message) {
117 //log.info(me + " : " + String.valueOf(message));
118 }
119
120 /**
121 * Log a message and exception with info log level.
122 */
123 public void info(Object message, Throwable exception) {
124 //log.info(me + " : " + String.valueOf(message) + " : " + exception.getMessage());
125 }
126
127 /**
128 * Log a message with trace log level.
129 */
130 public void trace(Object message) {
131 //if (log.debugState())
132 //log.debug(String.valueOf(message));
133 }
134
135 /**
136 * Log a message and exception with trace log level.
137 */
138 public void trace(Object message, Throwable exception) {
139 //if (log.debugState())
140 //log.debug(String.valueOf(message) + " : " + exception.getMessage());
141 }
142
143 /**
144 * Log a message with warn log level.
145 */
146 public void warn(Object message) {
147 //log.info(me + " : " + String.valueOf(message));
148 }
149
150 /**
151 * Log a message and exception with warn log level.
152 */
153 public void warn(Object message, Throwable exception) {
154 //log.info(me + " : " + String.valueOf(message) + " : " + exception.getMessage());
155 }
156
157 /**
158 * Is debug logging currently enabled?
159 */
160 public boolean isDebugEnabled() {
161 return (log.debugState());
162 }
163
164 /**
165 * Is error logging currently enabled?
166 */
167 public boolean isErrorEnabled() {
168 return (true);
169 }
170
171 /**
172 * Is fatal logging currently enabled?
173 */
174 public boolean isFatalEnabled() {
175 return (true);
176 }
177
178 /**
179 * Is info logging currently enabled?
180 */
181 public boolean isInfoEnabled() {
182 return (true);
183 }
184
185 /**
186 * Is tace logging currently enabled?
187 */
188 public boolean isTraceEnabled() {
189 return (log.debugState());
190 }
191
192 /**
193 * Is warning logging currently enabled?
194 */
195 public boolean isWarnEnabled() {
196 return (true);
197 }
198
199 }
|