Apollo配置中心动态刷新日志级别

  • 添加次配置后,当在apollo上面调整日志级别不需要重启服务器,马上就能生效
/**
* 结合apollo动态刷新日志级别
* @author: nj
* @date: 2019/1/21:下午5:00
*/
@Configuration
public class LogListenerConfig {
private static final Logger logger = LoggerFactory.getLogger(LoggerConfiguration.class);
/**
* 监听关键字,当配置中心的依次开头的配置发生变化时,日志级别刷新
*/
private static final String LOGGER_TAG = "loggers.root."; @Autowired
private LoggingSystem loggingSystem; /**
* 可以指定具体的namespace,未指定时使用的是 application这个namespace
*/
@ApolloConfig
private Config config; @ApolloConfigChangeListener
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);
loggingSystem.setLogLevel("", level);
logger.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;
}
}

Apollo配置中心动态刷新日志级别的更多相关文章

  1. 基于winserver的Apollo配置中心分布式&集群部署实践(正确部署姿势)

    基于winserver的Apollo配置中心分布式&集群部署实践(正确部署姿势)   前言 前几天对Apollo配置中心的demo进行一个部署试用,现公司已决定使用,这两天进行分布式部署的时候 ...

  2. Apollo配置中心

    背景: 当前我们项目,所有的配置基本都是通过本地properties 文件进行配置的,比如ip地址.端口.消息中间件和数据库连接的各种参数,当我们需要切换环境或调整参数的时候,我们必须手动的修改这些配 ...

  3. apollo配置中心初探

    近在搞微服务框架的开发,需要有一个配置中心来满足统一管理业务应用以及组件的配置,在此期间也使用了多个配置中心比如:spring cloud config,自研的配置中心,当然还有apollo. spr ...

  4. Apollo配置中心转

    尊重原创,本文转自:https://www.cnblogs.com/FlyAway2013/p/8811385.html 前我们项目,所有的配置基本都是通过本地properties 文件进行配置的,比 ...

  5. Win10上部署Apollo配置中心

    基于Docker在Win10上部署Apollo配置中心 https://www.jianshu.com/p/a1215056ce75 http://nobodyiam.com/2016/07/09/i ...

  6. Spring Boot 2.0 整合携程Apollo配置中心

    原文:https://www.jianshu.com/p/23d695af7e80 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够 ...

  7. Apollo配置中心介绍与使用指南

    转载于https://github.com/ctripcorp/apollo,by Ctrip, Inc. Apollo配置中心介绍 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中 ...

  8. Spring Cloud 系列之 Apollo 配置中心(一)

    背景 随着程序功能的日益复杂,程序的配置日益增多:各种功能的开关.参数的配置.服务器的地址等等. 对程序配置的期望值也越来越高:配置修改后实时生效,灰度发布,分环境.分集群管理配置,完善的权限.审核机 ...

  9. Spring Cloud 系列之 Apollo 配置中心(四)

    本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Apollo 配置中心(一) Spring Cloud 系列之 Apollo 配置中心(二) Spring Clou ...

随机推荐

  1. 36ArcGIS API for JavaScript3.X 系列加载天地图(经纬度)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. c# ef 排序字段动态,构建动态Lambda和扩展方法OrderBy

    1.动态构建排序 Lambda /// <summary> /// 获取排序Lambda(如果动态排序,类型不同会导致转换失败) /// </summary> /// < ...

  3. [运维工具]linux下远程桌面rdesktop安装和使用

    依然是解压 configure make make install 这些步骤 rdesktop -f 16 192.168.16.90 -f是全屏,退出全屏是CRTL+ALT+ENTER 记录一个li ...

  4. 微信小程序没有返回按钮怎么办?微信小程序左上角返回按钮怎么调出来?

    如果你发现自己的小程序页面没有返回按钮,请检查是不是用的wx.redirectTo(OBJECT)进行的跳转,如果是那就把它改成wx.navigateTo(OBJECT)就可以了. wx.naviga ...

  5. Batch入门教程丨第一章:部署与Hello World!(下)

    在上期分享的内容中,我们已经掌握了基础理论知识,今天我们将继续了解和学习与Windows Batch有关的知识和编程方法,如何编写和运行Windows Batch程序,脚本语言的入门方式等,从而能够更 ...

  6. SEO需要掌握的基础知识

    什么是SEO?  官方解释:  SEO是指通过对网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键词排名, 从而把精准用户带到网站,获得免费流量,产生直接销售或品牌推广 ...

  7. [Java]LeetCode133. 克隆图 | Clone Graph

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  8. [Swift]LeetCode376. 摆动序列 | Wiggle Subsequence

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  9. [Swift]LeetCode761. 特殊的二进制序列 | Special Binary String

    Special binary strings are binary strings with the following two properties: The number of 0's is eq ...

  10. Shell脚本中的for case while循环流程控制语句的使用

    shell作为一种脚本编程语言,同样包含循环.分支等其他程序控制结构,从而轻松完成更加复杂.强大的功能. 编写脚本的思路 1  明确脚本的功能 2  编写脚本时会使用到那些命令 ?   3  把变化的 ...