-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathLogger.java
969 lines (873 loc) · 33.9 KB
/
Logger.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.logmanager;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Supplier;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
/**
* An actual logger instance. This is the end-user interface into the logging system.
*/
@SuppressWarnings({ "SerializableClassWithUnconstructableAncestor" })
public final class Logger extends java.util.logging.Logger implements Serializable {
private static final long serialVersionUID = 5093333069125075416L;
private static final ResourceBundle TOMBSTONE = new ResourceBundle() {
@Override
protected Object handleGetObject(final String key) {
return null;
}
@Override
public Enumeration<String> getKeys() {
return null;
}
};
/**
* The named logger tree node.
*/
private final LoggerNode loggerNode;
/**
* The resource bundle for this logger.
*/
private volatile ResourceBundle resourceBundle;
private static final String LOGGER_CLASS_NAME = Logger.class.getName();
/**
* Static logger factory method which returns a JBoss LogManager logger.
*
* @param name the logger name
* @return the logger
*/
public static Logger getLogger(final String name) {
return LogContext.getLogContext().getLogger(name);
}
/**
* Static logger factory method which returns a JBoss LogManager logger.
*
* @param name the logger name
* @param bundleName the bundle name
* @return the logger
*/
public static Logger getLogger(final String name, final String bundleName) {
final Logger logger = LogContext.getLogContext().getLogger(name);
logger.resourceBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault(), Logger.class.getClassLoader());
return logger;
}
/**
* Construct a new instance of an actual logger.
*
* @param loggerNode the node in the named logger tree
* @param name the fully-qualified name of this node
*/
Logger(final LoggerNode loggerNode, final String name) {
// Don't set up the bundle in the parent...
super(name, null);
// We have to propagate our level to an internal data structure in the superclass
super.setLevel(loggerNode.getLevel());
this.loggerNode = loggerNode;
}
// Serialization
protected final Object writeReplace() throws ObjectStreamException {
return new SerializedLogger(getName());
}
// Filter mgmt
/** {@inheritDoc} */
public void setFilter(Filter filter) throws SecurityException {
LogContext.checkAccess();
loggerNode.setFilter(filter);
}
/** {@inheritDoc} */
public Filter getFilter() {
return loggerNode.getFilter();
}
// Level mgmt
/**
* {@inheritDoc} This implementation grabs a lock, so that only one thread may update the log level of any
* logger at a time, in order to allow readers to never block (though there is a window where retrieving the
* log level reflects an older effective level than the actual level).
*/
public void setLevel(Level newLevel) throws SecurityException {
LogContext.checkAccess();
// We have to propagate our level to an internal data structure in the superclass
super.setLevel(newLevel);
loggerNode.setLevel(newLevel);
}
/**
* Set the log level by name. Uses the parent logging context's name registry; otherwise behaves
* identically to {@link #setLevel(Level)}.
*
* @param newLevelName the name of the level to set
* @throws SecurityException if a security manager exists and if the caller does not have LoggingPermission("control")
*/
public void setLevelName(String newLevelName) throws SecurityException {
setLevel(loggerNode.getContext().getLevelForName(newLevelName));
}
/**
* Get the effective numerical log level, inherited from the parent.
*
* @return the effective level
*/
public int getEffectiveLevel() {
return loggerNode.getEffectiveLevel();
}
/** {@inheritDoc} */
public Level getLevel() {
return loggerNode.getLevel();
}
/** {@inheritDoc} */
public boolean isLoggable(Level level) {
return loggerNode.isLoggableLevel(level.intValue());
}
// Attachment mgmt
/**
* Get the attachment value for a given key, or {@code null} if there is no such attachment.
*
* @param key the key
* @param <V> the attachment value type
* @return the attachment, or {@code null} if there is none for this key
*/
@SuppressWarnings({ "unchecked" })
public <V> V getAttachment(AttachmentKey<V> key) {
return loggerNode.getAttachment(key);
}
/**
* Attach an object to this logger under a given key.
* A strong reference is maintained to the key and value for as long as this logger exists.
*
* @param key the attachment key
* @param value the attachment value
* @param <V> the attachment value type
* @return the old attachment, if there was one
* @throws SecurityException if a security manager exists and if the caller does not have
* {@code LoggingPermission(control)}
* @throws IllegalArgumentException if the attachment cannot be added because the maximum has been reached
*/
public <V> V attach(AttachmentKey<V> key, V value) throws SecurityException {
LogContext.checkAccess();
return loggerNode.attach(key, value);
}
/**
* Attach an object to this logger under a given key, if such an attachment does not already exist.
* A strong reference is maintained to the key and value for as long as this logger exists.
*
* @param key the attachment key
* @param value the attachment value
* @param <V> the attachment value type
* @return the current attachment, if there is one, or {@code null} if the value was successfully attached
* @throws SecurityException if a security manager exists and if the caller does not have
* {@code LoggingPermission(control)}
* @throws IllegalArgumentException if the attachment cannot be added because the maximum has been reached
*/
@SuppressWarnings({ "unchecked" })
public <V> V attachIfAbsent(AttachmentKey<V> key, V value) throws SecurityException {
LogContext.checkAccess();
return loggerNode.attachIfAbsent(key, value);
}
/**
* Remove an attachment.
*
* @param key the attachment key
* @param <V> the attachment value type
* @return the old value, or {@code null} if there was none
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
@SuppressWarnings({ "unchecked" })
public <V> V detach(AttachmentKey<V> key) throws SecurityException {
LogContext.checkAccess();
return loggerNode.detach(key);
}
// Handler mgmt
/** {@inheritDoc} */
public void addHandler(Handler handler) throws SecurityException {
LogContext.checkAccess();
if (handler == null) {
throw new NullPointerException("handler is null");
}
loggerNode.addHandler(handler);
}
/** {@inheritDoc} */
public void removeHandler(Handler handler) throws SecurityException {
LogContext.checkAccess();
if (handler == null) {
return;
}
loggerNode.removeHandler(handler);
}
/** {@inheritDoc} */
public Handler[] getHandlers() {
final Handler[] handlers = loggerNode.getHandlers();
return handlers.length > 0 ? handlers.clone() : handlers;
}
/**
* A convenience method to atomically replace the handler list for this logger.
*
* @param handlers the new handlers
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
public void setHandlers(final Handler[] handlers) throws SecurityException {
LogContext.checkAccess();
final Handler[] safeHandlers = handlers.clone();
for (Handler handler : safeHandlers) {
if (handler == null) {
throw new IllegalArgumentException("A handler is null");
}
}
loggerNode.setHandlers(safeHandlers);
}
/**
* Atomically get and set the handler list for this logger.
*
* @param handlers the new handler set
* @return the old handler set
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
public Handler[] getAndSetHandlers(final Handler[] handlers) throws SecurityException {
LogContext.checkAccess();
final Handler[] safeHandlers = handlers.clone();
for (Handler handler : safeHandlers) {
if (handler == null) {
throw new IllegalArgumentException("A handler is null");
}
}
return loggerNode.setHandlers(safeHandlers);
}
/**
* Atomically compare and set the handler list for this logger.
*
* @param expected the expected list of handlers
* @param newHandlers the replacement list of handlers
* @return {@code true} if the handler list was updated or {@code false} if the current handlers did not match the expected
* handlers list
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
public boolean compareAndSetHandlers(final Handler[] expected, final Handler[] newHandlers) throws SecurityException {
LogContext.checkAccess();
final Handler[] safeExpectedHandlers = expected.clone();
final Handler[] safeNewHandlers = newHandlers.clone();
for (Handler handler : safeNewHandlers) {
if (handler == null) {
throw new IllegalArgumentException("A handler is null");
}
}
Handler[] oldHandlers;
do {
oldHandlers = loggerNode.getHandlers();
if (!Arrays.equals(oldHandlers, safeExpectedHandlers)) {
return false;
}
} while (!loggerNode.compareAndSetHandlers(oldHandlers, safeNewHandlers));
return true;
}
/**
* A convenience method to atomically get and clear all handlers.
*
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
public Handler[] clearHandlers() throws SecurityException {
LogContext.checkAccess();
return loggerNode.clearHandlers();
}
/** {@inheritDoc} */
public void setUseParentHandlers(boolean useParentHandlers) {
LogContext.checkAccess();
loggerNode.setUseParentHandlers(useParentHandlers);
}
/** {@inheritDoc} */
public boolean getUseParentHandlers() {
return loggerNode.getUseParentHandlers();
}
/**
* Specify whether or not filters should be inherited from parent loggers.
* <p>
* Setting this value to {@code false} has the same behaviour as {@linkplain java.util.logging.Logger}.
* </p>
*
* @param useParentFilter {@code true} to inherit a parents filter, otherwise {@code false}
*/
public void setUseParentFilters(final boolean useParentFilter) {
LogContext.checkAccess();
loggerNode.setUseParentFilters(useParentFilter);
}
/**
* Indicates whether or not this logger inherits filters from it's parent logger.
*
* @return {@code true} if filters are inherited, otherwise {@code false}
*/
public boolean getUseParentFilters() {
return loggerNode.getUseParentFilters();
}
// Parent/child
/** {@inheritDoc} */
public Logger getParent() {
final LoggerNode parentNode = loggerNode.getParent();
return parentNode == null ? null : parentNode.createLogger();
}
/**
* <b>Not allowed.</b> This method may never be called.
*
* @throws SecurityException always
*/
public void setParent(java.util.logging.Logger parent) {
throw new SecurityException("setParent() disallowed");
}
/**
* Get the log context to which this logger belongs.
*
* @return the log context
*/
public LogContext getLogContext() {
return loggerNode.getContext();
}
// Logger
static final int OFF_INT = Level.OFF.intValue();
static final int SEVERE_INT = Level.SEVERE.intValue();
static final int WARNING_INT = Level.WARNING.intValue();
static final int INFO_INT = Level.INFO.intValue();
static final int CONFIG_INT = Level.CONFIG.intValue();
static final int FINE_INT = Level.FINE.intValue();
static final int FINER_INT = Level.FINER.intValue();
static final int FINEST_INT = Level.FINEST.intValue();
/** {@inheritDoc} */
public void log(LogRecord record) {
if (!loggerNode.isLoggableLevel(record.getLevel().intValue())) {
return;
}
logRaw(record);
}
/** {@inheritDoc} */
public void entering(final String sourceClass, final String sourceMethod) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "ENTRY", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
}
/** {@inheritDoc} */
public void entering(final String sourceClass, final String sourceMethod, final Object param1) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "ENTRY {0}", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { param1 });
logRaw(rec);
}
/** {@inheritDoc} */
public void entering(final String sourceClass, final String sourceMethod, final Object[] params) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final StringBuilder builder = new StringBuilder("ENTRY");
if (params != null)
for (int i = 0; i < params.length; i++) {
builder.append(" {").append(i).append('}');
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, builder.toString(), LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null)
rec.setParameters(params);
logRaw(rec);
}
/** {@inheritDoc} */
public void exiting(final String sourceClass, final String sourceMethod) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "RETURN", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
}
/** {@inheritDoc} */
public void exiting(final String sourceClass, final String sourceMethod, final Object result) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "RETURN {0}", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { result });
logRaw(rec);
}
/** {@inheritDoc} */
public void throwing(final String sourceClass, final String sourceMethod, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "THROW", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
logRaw(rec);
}
/** {@inheritDoc} */
public void severe(final String msg) {
if (!loggerNode.isLoggableLevel(SEVERE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void severe(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(SEVERE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void warning(final String msg) {
if (!loggerNode.isLoggableLevel(WARNING_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void warning(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(WARNING_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void info(final String msg) {
if (!loggerNode.isLoggableLevel(INFO_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void info(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(INFO_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void config(final String msg) {
if (!loggerNode.isLoggableLevel(CONFIG_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void config(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(CONFIG_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void fine(final String msg) {
if (!loggerNode.isLoggableLevel(FINE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void fine(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void finer(final String msg) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void finer(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void finest(final String msg) {
if (!loggerNode.isLoggableLevel(FINEST_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void finest(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINEST_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void log(final Level level, final String msg) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
logRaw(rec);
}
@Override
public void log(final Level level, final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
logRaw(rec);
}
/** {@inheritDoc} */
public void log(final Level level, final String msg, final Object param1) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setParameters(new Object[] { param1 });
logRaw(rec);
}
/** {@inheritDoc} */
public void log(final Level level, final String msg, final Object[] params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
if (params != null)
rec.setParameters(params);
logRaw(rec);
}
/** {@inheritDoc} */
public void log(final Level level, final String msg, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setThrown(thrown);
logRaw(rec);
}
@Override
public void log(final Level level, final Throwable thrown, final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
rec.setThrown(thrown);
logRaw(rec);
}
/** {@inheritDoc} */
public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
}
@Override
public void logp(final Level level, final String sourceClass, final String sourceMethod,
final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
}
/** {@inheritDoc} */
public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
final Object param1) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { param1 });
logRaw(rec);
}
/** {@inheritDoc} */
public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
final Object[] params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null)
rec.setParameters(params);
logRaw(rec);
}
/** {@inheritDoc} */
public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg,
final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
logRaw(rec);
}
@Override
public void logp(final Level level, final String sourceClass, final String sourceMethod, final Throwable thrown,
final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
logRaw(rec);
}
/** {@inheritDoc} */
@Deprecated(since = "3.0", forRemoval = true)
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
final String msg) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundleName, msg);
}
/** {@inheritDoc} */
@Deprecated(since = "3.0", forRemoval = true)
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
final String msg, final Object param1) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundleName, msg, param1);
}
/** {@inheritDoc} */
@Deprecated(since = "3.0", forRemoval = true)
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
final String msg, final Object[] params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundleName, msg, params);
}
/** {@inheritDoc} */
@Deprecated(since = "3.0", forRemoval = true)
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName,
final String msg, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundleName, msg, thrown);
}
@Override
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final ResourceBundle bundle,
final String msg, final Object... params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundle, msg, params);
}
@Override
public void logrb(final Level level, final ResourceBundle bundle, final String msg, final Object... params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, bundle, msg, params);
}
@Override
public void logrb(final Level level, final String sourceClass, final String sourceMethod, final ResourceBundle bundle,
final String msg, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, sourceClass, sourceMethod, bundle, msg, thrown);
}
@Override
public void logrb(final Level level, final ResourceBundle bundle, final String msg, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
// No local check is needed here as this will delegate to log(LogRecord)
super.logrb(level, bundle, msg, thrown);
}
// alternate SPI hooks
/**
* SPI interface method to log a message at a given level, with a specific resource bundle.
*
* @param fqcn the fully qualified class name of the first logger class
* @param level the level to log at
* @param message the message
* @param bundleName the resource bundle name
* @param style the message format style
* @param params the log parameters
* @param t the throwable, if any
*/
public void log(final String fqcn, final Level level, final String message, final String bundleName,
final ExtLogRecord.FormatStyle style, final Object[] params, final Throwable t) {
if (level == null || fqcn == null || message == null
|| !loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, message, style, fqcn);
rec.setResourceBundleName(bundleName);
rec.setParameters(params);
rec.setThrown(t);
logRaw(rec);
}
/**
* SPI interface method to log a message at a given level.
*
* @param fqcn the fully qualified class name of the first logger class
* @param level the level to log at
* @param message the message
* @param style the message format style
* @param params the log parameters
* @param t the throwable, if any
*/
public void log(final String fqcn, final Level level, final String message, final ExtLogRecord.FormatStyle style,
final Object[] params, final Throwable t) {
if (level == null || fqcn == null || message == null
|| !loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, message, style, fqcn);
rec.setParameters(params);
rec.setThrown(t);
logRaw(rec);
}
/**
* SPI interface method to log a message at a given level.
*
* @param fqcn the fully qualified class name of the first logger class
* @param level the level to log at
* @param message the message
* @param t the throwable, if any
*/
public void log(final String fqcn, final Level level, final String message, final Throwable t) {
log(fqcn, level, message, ExtLogRecord.FormatStyle.MESSAGE_FORMAT, null, t);
}
/**
* Do the logging with no level checks (they've already been done).
*
* @param record the extended log record
*/
public void logRaw(final ExtLogRecord record) {
record.setLoggerName(getName());
final ResourceBundle bundle = getResourceBundle();
if (bundle != null) {
record.setResourceBundleName(bundle.getBaseBundleName());
record.setResourceBundle(bundle);
}
try {
if (!loggerNode.isLoggable(record)) {
return;
}
} catch (VirtualMachineError e) {
throw e;
} catch (Throwable t) {
// todo - error handler
// treat an errored filter as "pass" (I guess?)
}
loggerNode.publish(record);
}
/**
* Set the resource bundle for this logger.
*
* @param resourceBundle the resource bundle (must not be {@code null})
*/
@Override
public void setResourceBundle(ResourceBundle resourceBundle) {
super.setResourceBundle(resourceBundle);
synchronized (this) {
this.resourceBundle = resourceBundle;
}
}
/**
* Get the resource bundle for this logger.
*
* @return the resource bundle, or {@code null} if none is configured for this logger
*/
@Override
public ResourceBundle getResourceBundle() {
if (resourceBundle == null) {
synchronized (this) {
if (resourceBundle == null) {
resourceBundle = super.getResourceBundle();
if (resourceBundle == null) {
resourceBundle = TOMBSTONE;
}
}
}
}
return resourceBundle == TOMBSTONE ? null : resourceBundle;
}
/**
* Do the logging with no level checks (they've already been done). Creates an extended log record if the
* provided record is not one.
*
* @param record the log record
*/
public void logRaw(final LogRecord record) {
logRaw(ExtLogRecord.wrap(record));
}
/**
* An attachment key instance.
*
* @param <V> the attachment value type
*/
@SuppressWarnings({ "UnusedDeclaration" })
public static final class AttachmentKey<V> {
/**
* Construct a new instance.
*/
public AttachmentKey() {
}
}
public String toString() {
return "Logger '" + getName() + "' in context " + loggerNode.getContext();
}
}