File tree 3 files changed +23
-2
lines changed
core/src/main/java/com/alipay/sofa/common/log
log-sofa-boot-starter/src
main/java/com/alipay/sofa/common/boot/logging
test/java/com/alipay/sofa/common/boot/logging/test
3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ public interface Constants {
77
77
String SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH = "sofa.middleware.log.console" ;
78
78
// single space switch to log on console
79
79
String SOFA_MIDDLEWARE_SINGLE_LOG_CONSOLE_SWITCH = "sofa.middleware.log.%s.console" ;
80
+ // console string
81
+ String CONSOLE_SUFFIX = ".console" ;
80
82
// sofa-common-tools 自身日志开关
81
83
// internal log level config.
82
84
String SOFA_MIDDLEWARE_LOG_INTERNAL_LEVEL = "sofa.middleware.log.internal.level" ;
Original file line number Diff line number Diff line change @@ -59,10 +59,11 @@ public void setReInitialize(boolean value) {
59
59
public void reInitializeLog (Map <String , String > context ) {
60
60
for (String key : context .keySet ()) {
61
61
if (key .startsWith (Constants .SOFA_MIDDLEWARE_CONFIG_PREFIX )
62
- && !key .equals (Constants .SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH )) {
62
+ && !key .equals (Constants .SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH )
63
+ && key .endsWith (Constants .CONSOLE_SUFFIX )) {
63
64
int index = Constants .SOFA_MIDDLEWARE_CONFIG_PREFIX .length ();
64
65
// minus length of .console
65
- int end = key .length () - 8 ;
66
+ int end = key .length () - Constants . CONSOLE_SUFFIX . length () ;
66
67
String spaceId = key .substring (index , end );
67
68
LoggerSpaceManager .getLoggerBySpace (spaceId , spaceId );
68
69
}
Original file line number Diff line number Diff line change @@ -356,6 +356,24 @@ public void testThreadContextConfiguration() {
356
356
}
357
357
}
358
358
359
+ /**
360
+ * test sofa.middleware.log.disable
361
+ */
362
+ @ Test
363
+ public void testDisableMiddleLog () {
364
+ Map <String , Object > properties = new HashMap <String , Object >();
365
+ properties .put (Constants .SOFA_MIDDLEWARE_LOG_DISABLE_PROP_KEY , "true" );
366
+ SpringApplication springApplication = new SpringApplication (EmptyConfig .class );
367
+ springApplication .setDefaultProperties (properties );
368
+ springApplication .run (new String [] {});
369
+ logger .info ("global space console" );
370
+ logger .debug ("global space console debug" );
371
+ Assert .assertFalse (outContent .toString ().contains ("global space console" ));
372
+ Assert .assertFalse (outContent .toString ().contains ("global space console debug" ));
373
+ LogEnvUtils .processGlobalSystemLogProperties ().remove (
374
+ Constants .SOFA_MIDDLEWARE_LOG_DISABLE_PROP_KEY );
375
+ }
376
+
359
377
protected File getLogbackDefaultFile (Environment environment ) {
360
378
String loggingRoot = environment .getProperty (Constants .LOG_PATH_PREFIX + TEST_SPACE );
361
379
if (StringUtil .isBlank (loggingRoot )) {
You can’t perform that action at this time.
0 commit comments