java - Configure Log4J 2 programatically using a dynamically generated YAML file
问题描述
I need to dynamically configure Log4j 2 with a YAML configuration loaded from a web service.
Is there any way to load this configuration?
My best approach has been to download the YAML configuration and write it to a temp file, then make Log4j 2 load it. It is working, but it doesn't feel good.
File f = File.createTempFile("config",".yaml");
Files.write(f.toPath(),yamlString.getBytes());
Configurator.initialize(null, f.getAbsolutePath());
f.delete();
Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
LOGGER.info("This is a INFO message");
Shortened, I would like to be able to:
ConfigurationSource source = new ConfigurationSource(new ByteArrayInputStream(yamlString.getBytes()));
Configurator.initialize(new YamlConfiguration(null,source));
Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
LOGGER.info("This is a INFO message");
解决方案
推荐阅读
- r - 在条件 for 循环中分配 NA
- google-cloud-functions - 如何使用谷歌云构建在一个源存储库中为多个谷歌云功能实施 CI/CD?
- amazon-ec2 - 如何将 AWS EC2 安全组中的 Atlassian/Bitbucket IP 列入白名单?
- javascript - 根据 ajax 返回的数据渲染 Html 选择列表
- javascript - 散景仪表板:有什么方法可以保存用户选择以重新加载页面?
- python - 从元组列表中获取具有“NaN”的元组索引
- android - Recyclerview 没有在 android 中更新
- pip - LinAlgError:不是正定的,即使有抖动。使用 conda 环境而不是 pip 时
- assembly - 如何在 Emu8086 汇编语言中显示用户的输入
- javascript - 将数据从html表导出到csv文件时如何删除列?