1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.core.logging.ri.jdk14;
22
23 import java.util.logging.Level;
24 import org.jdtaus.core.container.ContainerFactory;
25 import org.jdtaus.core.logging.spi.Logger;
26
27
28
29
30
31
32
33
34
35
36
37 public class JDK14Logger implements Logger
38 {
39
40
41
42
43
44
45 public JDK14Logger()
46 {
47 super();
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 public java.lang.String getName()
64 {
65 return (java.lang.String) ContainerFactory.getContainer().
66 getProperty( this, "name" );
67
68 }
69
70
71
72
73
74
75 public boolean isDebugEnabled()
76 {
77 return this.getLogger().isLoggable( Level.FINE );
78 }
79
80 public void debug( final String message )
81 {
82 this.log( Level.FINE, message, null );
83 }
84
85 public void debug( final Throwable throwable )
86 {
87 this.log( Level.FINE, throwable.getMessage(), throwable );
88 }
89
90 public boolean isErrorEnabled()
91 {
92 return this.getLogger().isLoggable( Level.SEVERE );
93 }
94
95 public void error( final String message )
96 {
97 this.log( Level.SEVERE, message, null );
98 }
99
100 public void error( final Throwable throwable )
101 {
102 this.log( Level.SEVERE, throwable.getMessage(), throwable );
103 }
104
105 public boolean isFatalEnabled()
106 {
107 return this.getLogger().isLoggable( Level.SEVERE );
108 }
109
110 public void fatal( final String message )
111 {
112 this.log( Level.SEVERE, message, null );
113 }
114
115 public void fatal( final Throwable throwable )
116 {
117 this.log( Level.SEVERE, throwable.getMessage(), throwable );
118 }
119
120 public boolean isInfoEnabled()
121 {
122 return this.getLogger().isLoggable( Level.INFO );
123 }
124
125 public void info( final String message )
126 {
127 this.log( Level.INFO, message, null );
128 }
129
130 public void info( final Throwable throwable )
131 {
132 this.log( Level.INFO, throwable.getMessage(), throwable );
133 }
134
135 public boolean isTraceEnabled()
136 {
137 return this.getLogger().isLoggable( Level.FINEST );
138 }
139
140 public void trace( final String message )
141 {
142 this.log( Level.FINEST, message, null );
143 }
144
145 public void trace( final Throwable throwable )
146 {
147 this.log( Level.FINEST, throwable.getMessage(), throwable );
148 }
149
150 public boolean isWarnEnabled()
151 {
152 return this.getLogger().isLoggable( Level.WARNING );
153 }
154
155 public void warn( final String message )
156 {
157 this.log( Level.WARNING, message, null );
158 }
159
160 public void warn( final Throwable throwable )
161 {
162 this.log( Level.WARNING, throwable.getMessage(), throwable );
163 }
164
165
166
167
168
169
170
171
172
173 public java.util.logging.Logger getLogger()
174 {
175 return java.util.logging.Logger.getLogger( this.getName() );
176 }
177
178 private void log( final Level level, final String msg, final Throwable t )
179 {
180 if ( this.getLogger().isLoggable( level ) )
181 {
182 StackTraceElement caller;
183 final Throwable x = new Throwable();
184 final StackTraceElement[] elements = x.getStackTrace();
185
186 String cname = "unknown";
187 String method = "unknown";
188
189 if ( elements != null && elements.length > 2 )
190 {
191 caller = elements[2];
192 cname = caller.getClassName();
193 method = caller.getMethodName();
194 }
195
196 if ( t == null )
197 {
198 this.getLogger().logp( level, cname, method, msg );
199 }
200 else
201 {
202 this.getLogger().logp( level, cname, method, msg, t );
203 }
204 }
205 }
206
207
208 }