如何以编程方式告诉 Logback 重新加载配置
我知道有一个 reloadDefaultConfiguration() jmx 操作,但是如果没有获取 MBean 实例并调用此操作,是否有 Logback api 来重新加载默认配置(可以选择指定日志配置文件路径)?
I know there's a reloadDefaultConfiguration() jmx operation, but without getting an instance of MBean and invoking this operation, is there a Logback api to reload the default configuration (optionally specifying a log configuration file path)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是
JMXConfigurator.reloadDefaultConfiguration()
的源代码:在需要的地方运行此代码怎么样?
唯一的问题是 loggerContext 变量。您可以使用以下方式获取它:
不幸的是,似乎没有精心设计的 API 可以执行此操作,那么如何提高 问题?您还知道 Logback 具有内置的自动刷新功能吗?
This is the source code of
JMXConfigurator.reloadDefaultConfiguration()
:What about just running this code wherever you need it?
The only problem is the
loggerContext
variable. You can obtain it using:Unfortunately it doesn't look like there is well-factored API to do this, what about raising an issue? Also are you aware that Logback has a built-in auto-refreshing feature?
我为此目的使用了以下代码:
I used the following code for this purpose:
对于 logback 1.5.x 或更高版本,以下内容应该有效
With logback 1.5.x or later, the following should work