1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package org.jomc.logging.ri.jdk;
37
38 import java.util.logging.Level;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
64
65
66 public final class JdkLogger
67 implements
68 org.jomc.logging.Logger,
69 org.jomc.spi.Listener
70 {
71
72
73
74 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
75 public JdkLogger()
76 {
77
78 super();
79
80 }
81
82
83
84
85 public boolean isDebugEnabled()
86 {
87 return this.getLogger().isLoggable( Level.FINE );
88 }
89
90 public void debug( final String message )
91 {
92 this.log( Level.FINE, message, null );
93 }
94
95 public void debug( final Throwable throwable )
96 {
97 this.log( Level.FINE, throwable.getMessage(), throwable );
98 }
99
100 public void debug( final String message, final Throwable throwable )
101 {
102 this.log( Level.FINE, message, throwable );
103 }
104
105 public boolean isErrorEnabled()
106 {
107 return this.getLogger().isLoggable( Level.SEVERE );
108 }
109
110 public void error( final String message )
111 {
112 this.log( Level.SEVERE, message, null );
113 }
114
115 public void error( final Throwable throwable )
116 {
117 this.log( Level.SEVERE, throwable.getMessage(), throwable );
118 }
119
120 public void error( final String message, final Throwable throwable )
121 {
122 this.log( Level.SEVERE, message, throwable );
123 }
124
125 public boolean isFatalEnabled()
126 {
127 return this.getLogger().isLoggable( Level.SEVERE );
128 }
129
130 public void fatal( final String message )
131 {
132 this.log( Level.SEVERE, message, null );
133 }
134
135 public void fatal( final Throwable throwable )
136 {
137 this.log( Level.SEVERE, throwable.getMessage(), throwable );
138 }
139
140 public void fatal( final String message, final Throwable throwable )
141 {
142 this.log( Level.SEVERE, message, throwable );
143 }
144
145 public boolean isInfoEnabled()
146 {
147 return this.getLogger().isLoggable( Level.INFO );
148 }
149
150 public void info( final String message )
151 {
152 this.log( Level.INFO, message, null );
153 }
154
155 public void info( final Throwable throwable )
156 {
157 this.log( Level.INFO, throwable.getMessage(), throwable );
158 }
159
160 public void info( final String message, final Throwable throwable )
161 {
162 this.log( Level.INFO, message, throwable );
163 }
164
165 public boolean isTraceEnabled()
166 {
167 return this.getLogger().isLoggable( Level.FINEST );
168 }
169
170 public void trace( final String message )
171 {
172 this.log( Level.FINEST, message, null );
173 }
174
175 public void trace( final Throwable throwable )
176 {
177 this.log( Level.FINEST, throwable.getMessage(), throwable );
178 }
179
180 public void trace( final String message, final Throwable throwable )
181 {
182 this.log( Level.FINEST, message, throwable );
183 }
184
185 public boolean isWarnEnabled()
186 {
187 return this.getLogger().isLoggable( Level.WARNING );
188 }
189
190 public void warn( final String message )
191 {
192 this.log( Level.WARNING, message, null );
193 }
194
195 public void warn( final Throwable throwable )
196 {
197 this.log( Level.WARNING, throwable.getMessage(), throwable );
198 }
199
200 public void warn( final String message, final Throwable throwable )
201 {
202 this.log( Level.WARNING, message, throwable );
203 }
204
205
206
207 public void onLog( final Level level, final String message, final Throwable throwable )
208 {
209 if ( level != null )
210 {
211 if ( level.equals( Level.CONFIG ) || level.equals( Level.FINE ) )
212 {
213 this.getObjectManagementLogger().debug( message, throwable );
214 }
215 else if ( level.equals( Level.FINER ) || level.equals( Level.FINEST ) )
216 {
217 this.getObjectManagementLogger().trace( message, throwable );
218 }
219 else if ( level.equals( Level.INFO ) )
220 {
221 this.getObjectManagementLogger().info( message, throwable );
222 }
223 else if ( level.equals( Level.SEVERE ) )
224 {
225 this.getObjectManagementLogger().error( message, throwable );
226 }
227 else if ( level.equals( Level.WARNING ) )
228 {
229 this.getObjectManagementLogger().warn( message, throwable );
230 }
231 else
232 {
233 this.getObjectManagementLogger().trace( message, throwable );
234 }
235 }
236 }
237
238
239
240
241
242
243
244
245
246
247
248 public java.util.logging.Logger getLogger()
249 {
250 return java.util.logging.Logger.getLogger( this.getName() );
251 }
252
253 private void log( final Level level, final String msg, final Throwable t )
254 {
255 if ( this.getLogger().isLoggable( level ) )
256 {
257 StackTraceElement caller;
258 final Throwable x = new Throwable();
259 final StackTraceElement[] elements = x.getStackTrace();
260
261 String cname = "unknown";
262 String method = "unknown";
263
264 if ( elements != null && elements.length >= this.getStackDepth() )
265 {
266 caller = elements[this.getStackDepth()];
267 cname = caller.getClassName();
268 method = caller.getMethodName();
269 }
270
271 if ( t == null )
272 {
273 this.getLogger().logp( level, cname, method, msg );
274 }
275 else
276 {
277 this.getLogger().logp( level, cname, method, msg, t );
278 }
279 }
280 }
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 @SuppressWarnings("unused")
317 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
318 private org.jomc.logging.Logger getObjectManagementLogger()
319 {
320 final org.jomc.logging.Logger _d = (org.jomc.logging.Logger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "ObjectManagementLogger" );
321 assert _d != null : "'ObjectManagementLogger' dependency not found.";
322 return _d;
323 }
324
325
326
327
328
329
330
331
332
333
334
335
336 @SuppressWarnings("unused")
337 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
338 public java.lang.String getName()
339 {
340 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "name" );
341 assert _p != null : "'name' property not found.";
342 return _p;
343 }
344
345
346
347
348
349
350
351
352 @SuppressWarnings("unused")
353 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
354 private int getStackDepth()
355 {
356 final java.lang.Integer _p = (java.lang.Integer) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "stackDepth" );
357 assert _p != null : "'stackDepth' property not found.";
358 return _p.intValue();
359 }
360
361
362
363
364 }