本文主要是介绍Apollo+LoggingSystem动态配置日志级别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
@ApolloConfig("namespace_xxxx.app_id") private Config config;@ApolloConfigChangeListener("namespace_xxxx.app_id") private void onChange(ConfigChangeEvent changeEvent) {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);logger.info("logging level changes {} : {}", ()->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; }
这篇关于Apollo+LoggingSystem动态配置日志级别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!