gpt4 book ai didi

spring - Log4j watch 和 Spring

转载 作者:行者123 更新时间:2023-12-04 04:56:30 25 4
gpt4 key购买 nike

所以我们使用 log4j 并希望在运行时更新它。我们不调用 spring 的 log4j 过滤器或 log4j 的 configure() 方法。我们按照许多文章的建议将 log4j.properties 放在类路径的根目录中,并且发生了某种使其加载的巫术。

但是现在,我们要添加监视线程以在运行时刷新 log4j.properties。我看到了 configureAndWatch,我看到 spring 在它的 log4j 加载上有一个计时器参数,但是由于我们的 log4j 是隐式加载的,我如何启动监视线程?

问题 2 - 监视线程会更新分配的记录器吗?我们的很多记录器都加载到静态成员中。他们会得到等级变化吗?

最佳答案

使用 org.springframework.util.Log4jConfigurer :

<util:list id="log4jProperties" list-class="java.util.ArrayList">
<value>classpath:log4j.properties</value>
<value>10000</value>
</util:list>

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
p:targetClass="org.springframework.util.Log4jConfigurer"
p:targetMethod="initLogging"
p:arguments-ref="log4jProperties" />

这将重新加载 log4j.properties 的内容每 10 秒。

关于spring - Log4j watch 和 Spring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16691186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com