apollo刷新日志相关属性

public class LoggerConfiguration {
    
    
    private static final Logger log = LoggerFactory.getLogger(LoggerConfiguration.class);
    private static final String LOGGER_TAG = "logging.level.";

    @Resource
    private LoggingSystem loggingSystem;

    @ApolloConfig
    private Config config;

    @ApolloConfigChangeListener(interestedKeyPrefixes = "logging")
    private void configChangeListener(ConfigChangeEvent changeEvent) {
    
    
        log.info("logger configure refresh");
        refreshLoggingLevels();
    }

    @PostConstruct
    private void refreshLoggingLevels() {
    
    
        Set<String> keyNames = config.getPropertyNames();
        for (String key : keyNames) {
    
    
            if (containsIgnoreCase(key, LOGGER_TAG)) {
    
    
                String strLevel = config.getProperty(key, "info");
                LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
                loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
                log.info("{}:{}", key, strLevel);
            }
        }
    }

    private static boolean containsIgnoreCase(String str, String searchStr) {
    
    
        if (str == null || searchStr == null) {
    
    
            return false;
        }
        int len = searchStr.length();
        int max = str.length() - len;
        for (int i = 0; i <= max; i++) {
    
    
            if (str.regionMatches(true, i, searchStr, 0, len)) {
    
    
                return true;
            }
        }
        return false;
    }
}

猜你喜欢

转载自blog.csdn.net/a807719447/article/details/112487107