1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package edu.internet2.middleware.grouperInstaller.util;
21
22 import edu.internet2.middleware.grouperInstallerExt.org.apache.commons.logging.Log;
23
24
25
26
27
28 public class GrouperInstallerLog implements Log {
29
30
31 private static ThreadLocal<Boolean> debugToConsole = new ThreadLocal<Boolean>();
32
33
34
35
36
37 public static void assignDebugToConsole(boolean theDebugToConsole) {
38 debugToConsole.set(theDebugToConsole);
39 }
40
41
42
43
44
45 public static boolean debugToConsole() {
46 Boolean debugToConsoleBoolean = debugToConsole.get();
47 return GrouperInstallerUtils.defaultIfNull(debugToConsoleBoolean, false);
48 }
49
50
51
52
53
54
55
56 private static void debugToConsoleIfNeeded(String prefix, Object message, Throwable t) {
57 if (debugToConsole()) {
58 System.err.print(prefix);
59 System.err.println(message);
60 if (t != null) {
61 t.printStackTrace();
62 }
63 }
64 }
65
66
67 private Log enclosedLog;
68
69
70
71
72
73 public GrouperInstallerLog(Log theLog) {
74 this.enclosedLog = theLog;
75 }
76
77
78
79
80 public void debug(Object message) {
81 debugToConsoleIfNeeded("DEBUG: ", message, null);
82 this.enclosedLog.debug(message);
83 }
84
85
86
87
88 public void debug(Object message, Throwable t) {
89 debugToConsoleIfNeeded("DEBUG: ", message, t);
90 this.enclosedLog.debug(message, t);
91 }
92
93
94
95
96 public void error(Object message) {
97 debugToConsoleIfNeeded("ERROR: ", message, null);
98 this.enclosedLog.error(message);
99 }
100
101
102
103
104 public void error(Object message, Throwable t) {
105 debugToConsoleIfNeeded("ERROR: ", message, t);
106 this.enclosedLog.error(message, t);
107 }
108
109
110
111
112 public void fatal(Object message) {
113 debugToConsoleIfNeeded("FATAL: ", message, null);
114 this.enclosedLog.fatal(message);
115 }
116
117
118
119
120 public void fatal(Object message, Throwable t) {
121 debugToConsoleIfNeeded("FATAL: ", message, t);
122 this.enclosedLog.fatal(message, t);
123 }
124
125
126
127
128 public void info(Object message) {
129 debugToConsoleIfNeeded("INFO: ", message, null);
130 this.enclosedLog.info(message);
131 }
132
133
134
135
136 public void info(Object message, Throwable t) {
137 debugToConsoleIfNeeded("INFO: ", message, t);
138 this.enclosedLog.info(message, t);
139 }
140
141
142
143
144 public boolean isDebugEnabled() {
145 return this.enclosedLog.isDebugEnabled();
146 }
147
148
149
150
151 public boolean isErrorEnabled() {
152 return this.enclosedLog.isErrorEnabled();
153 }
154
155
156
157
158 public boolean isFatalEnabled() {
159 return this.enclosedLog.isFatalEnabled();
160 }
161
162
163
164
165 public boolean isInfoEnabled() {
166 return this.enclosedLog.isInfoEnabled();
167 }
168
169
170
171
172 public boolean isTraceEnabled() {
173 return this.enclosedLog.isTraceEnabled();
174 }
175
176
177
178
179 public boolean isWarnEnabled() {
180 return this.enclosedLog.isWarnEnabled();
181 }
182
183
184
185
186 public void trace(Object message) {
187 debugToConsoleIfNeeded("TRACE: ", message, null);
188 this.enclosedLog.trace(message);
189 }
190
191
192
193
194 public void trace(Object message, Throwable t) {
195 debugToConsoleIfNeeded("TRACE: ", message, t);
196 this.enclosedLog.trace(message, t);
197 }
198
199
200
201
202 public void warn(Object message) {
203 debugToConsoleIfNeeded("WARN: ", message, null);
204 this.enclosedLog.warn(message);
205 }
206
207
208
209
210 public void warn(Object message, Throwable t) {
211 debugToConsoleIfNeeded("WARN: ", message, t);
212 this.enclosedLog.warn(message, t);
213 }
214
215 }