Logback 动态非配置化实现
程序员文章站
2022-05-10 17:22:03
...
public void main(String[] args){ private LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); SyslogAppender syslogAppender = new SyslogAppender(); syslogAppender.setSyslogHost("127.0.0.1"); syslogAppender.setPort(9000); syslogAppender.setName("LOGSYS"); syslogAppender.setFacility("LOCAL0"); syslogAppender.setContext(context); syslogAppender.setSuffixPattern("%d %-5level [%thread] %logger{0}: %msg%n"); syslogAppender.start(); AsyncAppender asyncSysLogAppender = new AsyncAppender(); asyncSysLogAppender.setContext(context); asyncSysLogAppender.setName("ASYNC_SYSLOG"); asyncSysLogAppender.setQueueSize(qianbaoProperties.getLogging().getLogstash().getQueueSize()); asyncSysLogAppender.addAppender(syslogAppender); asyncSysLogAppender.start(); context.getLogger("ROOT").addAppender(asyncSysLogAppender); LogbackLoggerContextListener loggerContextListener = new LogbackLoggerContextListener(); loggerContextListener.setContext(context); context.addListener(loggerContextListener); } class LogbackLoggerContextListener extends ContextAwareBase implements LoggerContextListener { @Override public boolean isResetResistant() { return true; } @Override public void onStart(LoggerContext context) { } @Override public void onReset(LoggerContext context) { } @Override public void onStop(LoggerContext context) { } @Override public void onLevelChange(ch.qos.logback.classic.Logger logger, Level level) { } }
推荐阅读
-
C#编程实现动态改变配置文件信息的方法
-
Spring Cloud动态配置实现原理与源码分析
-
小程序页面动态配置实现方法
-
Vue+ElementUI实现表单动态渲染、可视化配置的方法
-
Linux系统实现ansible自动化安装配置httpd的方法
-
在Nginx中配置image filter模块来实现动态生成缩略图
-
动态替换logback FileAppender/RollingFileAppender 配置- Programmatically configure logback FileAppender/RollingBackAppender
-
python实现可视化动态CPU性能监控
-
Redis连接池配置及初始化实现
-
.net core 基于Hangfire+Mysql持久化实现定时任务配置方法