1 package org.apache.maven.doxia.logging;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.PrintWriter;
23 import java.io.StringWriter;
24
25
26
27
28
29
30
31
32
33
34 @Deprecated
35 public class SystemStreamLog
36 implements Log
37 {
38 private static final String EOL = System.getProperty( "line.separator" );
39
40 private int currentLevel = LEVEL_INFO;
41
42
43 public void setLogLevel( int level )
44 {
45 if ( level <= LEVEL_DEBUG )
46 {
47 currentLevel = LEVEL_DEBUG;
48 }
49 else if ( level <= LEVEL_INFO )
50 {
51 currentLevel = LEVEL_INFO;
52 }
53 else if ( level <= LEVEL_WARN )
54 {
55 currentLevel = LEVEL_WARN;
56 }
57 else if ( level <= LEVEL_ERROR )
58 {
59 currentLevel = LEVEL_ERROR;
60 }
61 else
62 {
63 currentLevel = LEVEL_DISABLED;
64 }
65 }
66
67
68
69
70
71
72 public void debug( CharSequence content )
73 {
74 if ( isDebugEnabled() )
75 {
76 print( "debug", content );
77 }
78 }
79
80
81 public void debug( CharSequence content, Throwable error )
82 {
83 if ( isDebugEnabled() )
84 {
85 print( "debug", content, error );
86 }
87 }
88
89
90 public void debug( Throwable error )
91 {
92 if ( isDebugEnabled() )
93 {
94 print( "debug", error );
95 }
96 }
97
98
99 public void info( CharSequence content )
100 {
101 if ( isInfoEnabled() )
102 {
103 print( "info", content );
104 }
105 }
106
107
108 public void info( CharSequence content, Throwable error )
109 {
110 if ( isInfoEnabled() )
111 {
112 print( "info", content, error );
113 }
114 }
115
116
117
118
119
120
121 public void info( Throwable error )
122 {
123 if ( isInfoEnabled() )
124 {
125 print( "info", error );
126 }
127 }
128
129
130
131
132
133
134 public void warn( CharSequence content )
135 {
136 if ( isWarnEnabled() )
137 {
138 print( "warn", content );
139 }
140 }
141
142
143 public void warn( CharSequence content, Throwable error )
144 {
145 if ( isWarnEnabled() )
146 {
147 print( "warn", content, error );
148 }
149 }
150
151
152 public void warn( Throwable error )
153 {
154 if ( isWarnEnabled() )
155 {
156 print( "warn", error );
157 }
158 }
159
160
161 public void error( CharSequence content )
162 {
163 if ( isErrorEnabled() )
164 {
165 System.err.println( "[error] " + content.toString() );
166 }
167 }
168
169
170 public void error( CharSequence content, Throwable error )
171 {
172 if ( isErrorEnabled() )
173 {
174 StringWriter sWriter = new StringWriter();
175 PrintWriter pWriter = new PrintWriter( sWriter );
176
177 error.printStackTrace( pWriter );
178
179 System.err.println( "[error] " + content.toString()
180 + EOL + EOL + sWriter.toString() );
181 }
182 }
183
184
185
186
187
188
189 public void error( Throwable error )
190 {
191 if ( isErrorEnabled() )
192 {
193 StringWriter sWriter = new StringWriter();
194 PrintWriter pWriter = new PrintWriter( sWriter );
195
196 error.printStackTrace( pWriter );
197
198 System.err.println( "[error] " + sWriter.toString() );
199 }
200 }
201
202
203
204
205
206
207 public boolean isDebugEnabled()
208 {
209 return ( currentLevel <= LEVEL_DEBUG );
210 }
211
212
213
214
215
216
217 public boolean isInfoEnabled()
218 {
219 return ( currentLevel <= LEVEL_INFO );
220 }
221
222
223
224
225
226
227 public boolean isWarnEnabled()
228 {
229 return ( currentLevel <= LEVEL_WARN );
230 }
231
232
233
234
235
236
237 public boolean isErrorEnabled()
238 {
239 return ( currentLevel <= LEVEL_ERROR );
240 }
241
242
243
244
245
246 private void print( String prefix, CharSequence content )
247 {
248 System.out.println( "[" + prefix + "] " + content.toString() );
249 }
250
251 private void print( String prefix, Throwable error )
252 {
253 StringWriter sWriter = new StringWriter();
254 PrintWriter pWriter = new PrintWriter( sWriter );
255
256 error.printStackTrace( pWriter );
257
258 System.out.println( "[" + prefix + "] " + sWriter.toString() );
259 }
260
261 private void print( String prefix, CharSequence content, Throwable error )
262 {
263 StringWriter sWriter = new StringWriter();
264 PrintWriter pWriter = new PrintWriter( sWriter );
265
266 error.printStackTrace( pWriter );
267
268 System.out.println( "[" + prefix + "] " + content.toString()
269 + EOL + EOL + sWriter.toString() );
270 }
271 }