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
37
38
39
40 package io.netty5.util.internal.logging;
41
42 import java.util.logging.Level;
43 import java.util.logging.LogRecord;
44 import java.util.logging.Logger;
45
46
47
48
49
50 class JdkLogger extends AbstractInternalLogger {
51
52 private static final long serialVersionUID = -1767272577989225979L;
53
54 final transient Logger logger;
55
56 JdkLogger(Logger logger) {
57 super(logger.getName());
58 this.logger = logger;
59 }
60
61
62
63
64
65
66 @Override
67 public boolean isTraceEnabled() {
68 return logger.isLoggable(Level.FINEST);
69 }
70
71
72
73
74
75
76
77 @Override
78 public void trace(String msg) {
79 if (logger.isLoggable(Level.FINEST)) {
80 log(SELF, Level.FINEST, msg, null);
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 @Override
99 public void trace(String format, Object arg) {
100 if (logger.isLoggable(Level.FINEST)) {
101 FormattingTuple ft = MessageFormatter.format(format, arg);
102 log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
103 }
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 @Override
123 public void trace(String format, Object argA, Object argB) {
124 if (logger.isLoggable(Level.FINEST)) {
125 FormattingTuple ft = MessageFormatter.format(format, argA, argB);
126 log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
127 }
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 @Override
145 public void trace(String format, Object... argArray) {
146 if (logger.isLoggable(Level.FINEST)) {
147 FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
148 log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
149 }
150 }
151
152
153
154
155
156
157
158
159
160 @Override
161 public void trace(String msg, Throwable t) {
162 if (logger.isLoggable(Level.FINEST)) {
163 log(SELF, Level.FINEST, msg, t);
164 }
165 }
166
167
168
169
170
171
172 @Override
173 public boolean isDebugEnabled() {
174 return logger.isLoggable(Level.FINE);
175 }
176
177
178
179
180
181
182
183 @Override
184 public void debug(String msg) {
185 if (logger.isLoggable(Level.FINE)) {
186 log(SELF, Level.FINE, msg, null);
187 }
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203 @Override
204 public void debug(String format, Object arg) {
205 if (logger.isLoggable(Level.FINE)) {
206 FormattingTuple ft = MessageFormatter.format(format, arg);
207 log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
208 }
209 }
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 @Override
228 public void debug(String format, Object argA, Object argB) {
229 if (logger.isLoggable(Level.FINE)) {
230 FormattingTuple ft = MessageFormatter.format(format, argA, argB);
231 log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
232 }
233 }
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249 @Override
250 public void debug(String format, Object... argArray) {
251 if (logger.isLoggable(Level.FINE)) {
252 FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
253 log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
254 }
255 }
256
257
258
259
260
261
262
263
264
265 @Override
266 public void debug(String msg, Throwable t) {
267 if (logger.isLoggable(Level.FINE)) {
268 log(SELF, Level.FINE, msg, t);
269 }
270 }
271
272
273
274
275
276
277 @Override
278 public boolean isInfoEnabled() {
279 return logger.isLoggable(Level.INFO);
280 }
281
282
283
284
285
286
287
288 @Override
289 public void info(String msg) {
290 if (logger.isLoggable(Level.INFO)) {
291 log(SELF, Level.INFO, msg, null);
292 }
293 }
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308 @Override
309 public void info(String format, Object arg) {
310 if (logger.isLoggable(Level.INFO)) {
311 FormattingTuple ft = MessageFormatter.format(format, arg);
312 log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
313 }
314 }
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332 @Override
333 public void info(String format, Object argA, Object argB) {
334 if (logger.isLoggable(Level.INFO)) {
335 FormattingTuple ft = MessageFormatter.format(format, argA, argB);
336 log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
337 }
338 }
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354 @Override
355 public void info(String format, Object... argArray) {
356 if (logger.isLoggable(Level.INFO)) {
357 FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
358 log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
359 }
360 }
361
362
363
364
365
366
367
368
369
370
371 @Override
372 public void info(String msg, Throwable t) {
373 if (logger.isLoggable(Level.INFO)) {
374 log(SELF, Level.INFO, msg, t);
375 }
376 }
377
378
379
380
381
382
383
384 @Override
385 public boolean isWarnEnabled() {
386 return logger.isLoggable(Level.WARNING);
387 }
388
389
390
391
392
393
394
395 @Override
396 public void warn(String msg) {
397 if (logger.isLoggable(Level.WARNING)) {
398 log(SELF, Level.WARNING, msg, null);
399 }
400 }
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416 @Override
417 public void warn(String format, Object arg) {
418 if (logger.isLoggable(Level.WARNING)) {
419 FormattingTuple ft = MessageFormatter.format(format, arg);
420 log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
421 }
422 }
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440 @Override
441 public void warn(String format, Object argA, Object argB) {
442 if (logger.isLoggable(Level.WARNING)) {
443 FormattingTuple ft = MessageFormatter.format(format, argA, argB);
444 log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
445 }
446 }
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462 @Override
463 public void warn(String format, Object... argArray) {
464 if (logger.isLoggable(Level.WARNING)) {
465 FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
466 log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
467 }
468 }
469
470
471
472
473
474
475
476
477
478
479 @Override
480 public void warn(String msg, Throwable t) {
481 if (logger.isLoggable(Level.WARNING)) {
482 log(SELF, Level.WARNING, msg, t);
483 }
484 }
485
486
487
488
489
490
491 @Override
492 public boolean isErrorEnabled() {
493 return logger.isLoggable(Level.SEVERE);
494 }
495
496
497
498
499
500
501
502 @Override
503 public void error(String msg) {
504 if (logger.isLoggable(Level.SEVERE)) {
505 log(SELF, Level.SEVERE, msg, null);
506 }
507 }
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523 @Override
524 public void error(String format, Object arg) {
525 if (logger.isLoggable(Level.SEVERE)) {
526 FormattingTuple ft = MessageFormatter.format(format, arg);
527 log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
528 }
529 }
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547 @Override
548 public void error(String format, Object argA, Object argB) {
549 if (logger.isLoggable(Level.SEVERE)) {
550 FormattingTuple ft = MessageFormatter.format(format, argA, argB);
551 log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
552 }
553 }
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569 @Override
570 public void error(String format, Object... arguments) {
571 if (logger.isLoggable(Level.SEVERE)) {
572 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
573 log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
574 }
575 }
576
577
578
579
580
581
582
583
584
585
586 @Override
587 public void error(String msg, Throwable t) {
588 if (logger.isLoggable(Level.SEVERE)) {
589 log(SELF, Level.SEVERE, msg, t);
590 }
591 }
592
593
594
595
596
597
598
599
600 private void log(String callerFQCN, Level level, String msg, Throwable t) {
601
602 LogRecord record = new LogRecord(level, msg);
603 record.setLoggerName(name());
604 record.setThrown(t);
605 fillCallerData(callerFQCN, record);
606 logger.log(record);
607 }
608
609 static final String SELF = JdkLogger.class.getName();
610 static final String SUPER = AbstractInternalLogger.class.getName();
611
612
613
614
615
616
617
618 private static void fillCallerData(String callerFQCN, LogRecord record) {
619 StackTraceElement[] steArray = new Throwable().getStackTrace();
620
621 int selfIndex = -1;
622 for (int i = 0; i < steArray.length; i++) {
623 final String className = steArray[i].getClassName();
624 if (className.equals(callerFQCN) || className.equals(SUPER)) {
625 selfIndex = i;
626 break;
627 }
628 }
629
630 int found = -1;
631 for (int i = selfIndex + 1; i < steArray.length; i++) {
632 final String className = steArray[i].getClassName();
633 if (!(className.equals(callerFQCN) || className.equals(SUPER))) {
634 found = i;
635 break;
636 }
637 }
638
639 if (found != -1) {
640 StackTraceElement ste = steArray[found];
641
642
643 record.setSourceClassName(ste.getClassName());
644 record.setSourceMethodName(ste.getMethodName());
645 }
646 }
647 }