1
1
/**
2
2
* Logback: the reliable, generic, fast and flexible logging framework.
3
3
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4
- *
4
+ * <p>
5
5
* This program and the accompanying materials are dual-licensed under
6
6
* either the terms of the Eclipse Public License v1.0 as published by
7
7
* the Eclipse Foundation
8
- *
9
- * or (per the licensee's choosing)
10
- *
8
+ * <p>
9
+ * or (per the licensee's choosing)
10
+ * <p>
11
11
* under the terms of the GNU Lesser General Public License version 2.1
12
12
* as published by the Free Software Foundation.
13
13
*/
@@ -121,7 +121,7 @@ public void asyncWithMultipleAppendersInRoot() throws JoranException {
121
121
String msg = "hello world" ;
122
122
logger .warn (msg );
123
123
}
124
-
124
+
125
125
@ Test
126
126
public void simpleListWithImports () throws JoranException {
127
127
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "simpleListWithImports.xml" );
@@ -225,31 +225,31 @@ public void contextRename() throws JoranException {
225
225
@ Test
226
226
public void missingConfigurationElement () throws JoranException {
227
227
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/noConfig.xml" );
228
-
229
- String msg1 = "Exception in body\\ (\\ ) method for action \\ [" + ParamAction .class .getName ()+ "\\ ]" ;
228
+
229
+ String msg1 = "Exception in body\\ (\\ ) method for action \\ [" + ParamAction .class .getName () + "\\ ]" ;
230
230
checker .assertContainsMatch (Status .ERROR , msg1 );
231
-
231
+
232
232
String msg2 = "current model is null. Is <configuration> element missing?" ;
233
- checker .assertContainsException (ActionException .class , msg2 );
233
+ checker .assertContainsException (ActionException .class , msg2 );
234
234
}
235
235
236
236
@ Test
237
237
public void ignoreUnknownProperty () throws JoranException {
238
-
238
+
239
239
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/unknownProperty.xml" );
240
- String msg = IGNORING_UNKNOWN_PROP + " \\ [a\\ ] in \\ [ch.qos.logback.classic.LoggerContext\\ ]" ;
240
+ String msg = IGNORING_UNKNOWN_PROP + " \\ [a\\ ] in \\ [ch.qos.logback.classic.LoggerContext\\ ]" ;
241
241
checker .assertContainsMatch (Status .WARN , msg );
242
242
}
243
-
243
+
244
244
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=46995
245
245
@ Test
246
246
public void complexCollectionWihhNoKnownClass () throws JoranException {
247
-
248
- configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/nestedComplexWithNoKnownClass.xml" );
249
- String msg = "Could not find an appropriate class for property \\ [listener\\ ]" ;
250
- checker .assertContainsMatch (Status .ERROR , msg );
247
+
248
+ configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/nestedComplexWithNoKnownClass.xml" );
249
+ String msg = "Could not find an appropriate class for property \\ [listener\\ ]" ;
250
+ checker .assertContainsMatch (Status .ERROR , msg );
251
251
}
252
-
252
+
253
253
@ Test
254
254
public void turboFilter () throws JoranException {
255
255
// Although this test uses turbo filters, it only checks
@@ -296,7 +296,6 @@ public void testLevelFilter() throws JoranException {
296
296
}
297
297
298
298
299
-
300
299
@ Test
301
300
public void testTurboDynamicThreshold () throws JoranException {
302
301
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "turboDynamicThreshold.xml" );
@@ -452,7 +451,7 @@ public void unreferencedAppenderShouldNotTriggerUnknownPropertyMessages() throws
452
451
configure (configFileAsStr );
453
452
checker .assertContainsMatch (Status .WARN ,
454
453
"Appender named \\ [EMAIL\\ ] not referenced. Skipping further processing." );
455
- checker .assertNoMatch (IGNORING_UNKNOWN_PROP + " \\ [evaluator\\ ]" );
454
+ checker .assertNoMatch (IGNORING_UNKNOWN_PROP + " \\ [evaluator\\ ]" );
456
455
}
457
456
458
457
@ Test
@@ -546,7 +545,7 @@ public void nestedAppendersDisallowed() throws JoranException {
546
545
String configFileAsStr = ClassicTestConstants .JORAN_INPUT_PREFIX + "issues/logback_1674.xml" ;
547
546
configure (configFileAsStr );
548
547
checker .assertContainsMatch (Status .WARN , NESTED_APPENDERS_WARNING );
549
- checker .assertContainsMatch (Status .WARN ,"Appender at line " );
548
+ checker .assertContainsMatch (Status .WARN , "Appender at line " );
550
549
}
551
550
552
551
@ Test
@@ -622,13 +621,13 @@ public void missingPropertyErrorHandling() throws JoranException {
622
621
assertNotNull (listAppender );
623
622
assertTrue (listAppender .isStarted ());
624
623
checker .assertContainsMatch (Status .WARN ,
625
- IGNORING_UNKNOWN_PROP + " \\ [inexistent\\ ] in \\ [ch.qos.logback.core.read.ListAppender\\ ]" );
624
+ IGNORING_UNKNOWN_PROP + " \\ [inexistent\\ ] in \\ [ch.qos.logback.core.read.ListAppender\\ ]" );
626
625
}
627
626
628
627
@ Test
629
628
public void sequenceNumberGenerator () throws JoranException {
630
629
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "sequenceNumberGenerator.xml" );
631
- final ListAppender <ILoggingEvent > listAppender = (ListAppender <ILoggingEvent >) root .getAppender ("LIST" );
630
+ final ListAppender <ILoggingEvent > listAppender = (ListAppender <ILoggingEvent >) root .getAppender ("LIST" );
632
631
assertNotNull (listAppender );
633
632
634
633
logger .atDebug ().setMessage ("hello" ).log ();
@@ -646,12 +645,12 @@ public void sequenceNumberGenerator() throws JoranException {
646
645
public void sequenceNumberGenerator_missingClass () throws JoranException {
647
646
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "sequenceNumberGenerator-missingClass.xml" );
648
647
//StatusPrinter.print(loggerContext);
649
- final ListAppender <ILoggingEvent > listAppender = (ListAppender <ILoggingEvent >) root .getAppender ("LIST" );
648
+ final ListAppender <ILoggingEvent > listAppender = (ListAppender <ILoggingEvent >) root .getAppender ("LIST" );
650
649
assertNotNull (listAppender );
651
650
checker .assertContainsMatch (Status .ERROR , "Missing attribute \\ [class\\ ]. See element \\ [sequenceNumberGenerator\\ ]" );
652
651
}
653
652
654
- @ Test
653
+ @ Test
655
654
public void kvp () throws JoranException {
656
655
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "pattern/kvp.xml" );
657
656
@@ -680,7 +679,7 @@ public void kvp() throws JoranException {
680
679
681
680
// See LOGBACK-1746
682
681
@ Test
683
- public void inclusionWithVariables () throws JoranException {
682
+ public void inclusionWithVariables () throws JoranException {
684
683
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "include/topLevel0.xml" );
685
684
Logger root = loggerContext .getLogger (Logger .ROOT_LOGGER_NAME );
686
685
//statusPrinter2.print(loggerContext);
@@ -689,9 +688,9 @@ public void inclusionWithVariables() throws JoranException {
689
688
690
689
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=46697
691
690
@ Test
692
- public void ossFuzz_46697 () throws JoranException {
691
+ public void ossFuzz_46697 () throws JoranException {
693
692
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-46697.xml" );
694
-
693
+
695
694
checker .assertContainsMatch (Status .ERROR , ErrorCodes .EMPTY_MODEL_STACK );
696
695
}
697
696
@@ -700,62 +699,98 @@ public void ossFuzz_46697() throws JoranException {
700
699
// escape sequences for the 'value' attribute named 'value'. After
701
700
// analysis this was deemed superfluous.
702
701
@ Test
703
- public void ossFuzz_47093 () throws JoranException {
702
+ public void ossFuzz_47093 () throws JoranException {
704
703
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47093.xml" );
705
704
assertEquals ("a\\ t" , loggerContext .getProperty ("fuzz-47093-a" ));
706
705
assertEquals ("a\\ \\ " , loggerContext .getProperty ("fuzz-47093-b" ));
707
706
}
708
707
709
708
@ Test
710
- public void ossFuzz_41117 () throws JoranException {
709
+ public void ossFuzz_41117 () throws JoranException {
711
710
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47117.xml" );
712
711
checker .assertContainsMatch (Status .ERROR , ErrorCodes .ROOT_LEVEL_CANNOT_BE_SET_TO_NULL );
713
712
checker .assertErrorCount (2 );
714
713
//StatusPrinter.print(loggerContext);
715
714
}
716
715
717
716
@ Test
718
- public void ossFuzz_41117_bis () throws JoranException {
717
+ public void ossFuzz_41117_bis () throws JoranException {
719
718
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47117-bis.xml" );
720
719
checker .assertContainsMatch (Status .ERROR , ErrorCodes .ROOT_LEVEL_CANNOT_BE_SET_TO_NULL );
721
720
}
722
721
723
722
@ Test
724
- public void ossFuzz_41117_bis2 () throws JoranException {
723
+ public void ossFuzz_41117_bis2 () throws JoranException {
725
724
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47117-bis2.xml" );
726
725
checker .assertContainsMatch (Status .ERROR , ErrorCodes .ROOT_LEVEL_CANNOT_BE_SET_TO_NULL );
727
726
}
728
727
729
728
@ Test
730
- public void ossFuzz_47293 () throws JoranException {
729
+ public void ossFuzz_47293 () throws JoranException {
731
730
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "ossfuzz/fuzz-47293.xml" );
732
731
checker .assertContainsMatch (Status .ERROR , ErrorCodes .MISSING_IF_EMPTY_MODEL_STACK );
733
732
}
734
733
735
734
736
735
@ Test
737
- public void dateConverterWithLocale () throws JoranException {
736
+ public void dateConverterWithLocale () throws JoranException {
738
737
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "dateWithLocale.xml" );
739
738
checker .assertContainsMatch (Status .INFO , "Setting zoneId to \" Australia/Perth\" " );
740
739
checker .assertContainsMatch (Status .INFO , "Setting locale to \" en_AU\" " );
741
740
//StatusPrinter.print(loggerContext);
742
741
}
743
742
744
743
@ Test
745
- public void consoleCharsetTest () throws JoranException {
746
- if (EnvUtil .isJDK21OrHigher ()) {
744
+ public void consoleCharsetTest () throws JoranException {
745
+ if (EnvUtil .isJDK21OrHigher ()) {
747
746
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "consoleCharset.xml" );
748
747
checker .assertContainsMatch (Status .INFO , "About to instantiate property definer of type \\ [ch.qos.logback.core.property.ConsoleCharsetPropertyDefiner\\ ]" );
749
748
checker .assertContainsMatch (Status .WARN , "System.console\\ (\\ ) returned null. Cannot compute console's charset, returning" );
750
- checker .assertContainsMatch ("Setting property consoleCharset=null in scope LOCAL" );
749
+ checker .assertContainsMatch ("Setting property consoleCharset=null in scope LOCAL" );
751
750
checker .assertContainsMatch ("Converting the string \\ \" null. as Charset.defaultCharset\\ (\\ )" );
752
751
//StatusPrinter.print(loggerContext);
753
752
}
754
753
}
755
754
755
+ @ Test
756
+ public void levelFromAPropertyTest () throws JoranException {
757
+
758
+
759
+ String loggerASysLevelKey = "LOGGER_A_SYS_LEVEL" ;
760
+ String loggerNestedSysLevelKey = "LOGGER_NESTED_SYS_LEVEL" ;
761
+ System .setProperty (loggerASysLevelKey , "WARN" );
762
+ System .setProperty (loggerNestedSysLevelKey , "ERROR" );
763
+ configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "levelFromAProperty.xml" );
764
+
765
+
766
+ Logger root = loggerContext .getLogger (Logger .ROOT_LOGGER_NAME );
767
+
768
+
769
+ Logger loggerA = loggerContext .getLogger ("A" );
770
+ Logger loggerA_SYS = loggerContext .getLogger ("A_SYS" );
771
+
772
+ Logger loggerNESTED = loggerContext .getLogger ("NESTED" );
773
+
774
+ Logger loggerNESTED_SYS = loggerContext .getLogger ("NESTED_SYS" );
775
+
776
+
777
+ assertEquals (Level .TRACE , root .getLevel ());
778
+ assertEquals (Level .WARN , loggerA .getLevel ());
779
+ assertEquals (Level .WARN , loggerA_SYS .getLevel ());
780
+
781
+ assertEquals (Level .ERROR , loggerNESTED .getLevel ());
782
+ assertEquals (Level .ERROR , loggerNESTED_SYS .getLevel ());
783
+
784
+ checker .assertContainsMatch (Status .INFO , "value \\ \" WARN\\ \" substituted for \\ \" \\ $\\ {LOGGER_A_LEVEL\\ }\\ \" " );
785
+
786
+ System .clearProperty (loggerASysLevelKey );
787
+ System .clearProperty (loggerNestedSysLevelKey );
788
+
789
+ }
790
+
756
791
@ Test
757
792
public void modelSerialization () throws JoranException , IOException , ClassNotFoundException {
758
- String outputPath = OUTPUT_DIR_PREFIX + "minimal_" + diff + MODEL_CONFIG_FILE_EXTENSION ;
793
+ String outputPath = OUTPUT_DIR_PREFIX + "minimal_" + diff + MODEL_CONFIG_FILE_EXTENSION ;
759
794
760
795
loggerContext .putProperty ("targetModelFile" , outputPath );
761
796
configure (ClassicTestConstants .JORAN_INPUT_PREFIX + "model/minimal.xml" );
@@ -775,25 +810,20 @@ public void modelSerialization() throws JoranException, IOException, ClassNotFou
775
810
776
811
assertEquals (2 , configurationModel .getSubModels ().size ());
777
812
778
- SerializeModelModel smm = (SerializeModelModel ) configurationModel .getSubModels ().get (0 );
813
+ SerializeModelModel smm = (SerializeModelModel ) configurationModel .getSubModels ().get (0 );
779
814
assertEquals ("${targetModelFile}" , smm .getFile ());
780
815
781
816
782
- LoggerModel loggerModel = (LoggerModel ) configurationModel .getSubModels ().get (1 );
817
+ LoggerModel loggerModel = (LoggerModel ) configurationModel .getSubModels ().get (1 );
783
818
assertEquals ("ModelSerializationTest" , loggerModel .getName ());
784
819
785
820
// <serializeModel file="${targetModelFile}"/>
786
821
// <logger name="ModelSerializationTest" level="DEBUG"/>
787
822
788
823
789
-
790
824
}
791
825
792
826
793
-
794
-
795
-
796
-
797
827
// reproduction requires placing a binary properties file. Probably not worth the effort.
798
828
// @Test
799
829
// public void ossFuzz_47249() throws JoranException {
0 commit comments