Perl 的 Log::Log4perl 的日志级别可以在不更新配置的情况下动态更改吗?
我有一个在 mod_perl 下运行的 Mason 模板,它使用 Log::Log4perl。
我想更改特定附加程序的日志级别,但更改配置太尴尬了,因为它必须通过我们的部署过程才能上线。
有没有办法在 Apache 启动后在运行时更改附加程序的日志级别,而不更改配置文件,然后该更改会影响任何新的 Apache 线程?
I have a Mason template running under mod_perl, which is using Log::Log4perl.
I want to change the log level of a particular appender, but changing the config is too awkward, as it would have to pass through our deployment process to go live.
Is there a way to change the log level of an appender at run-time, after Apache has started, without changing the config file, and then have that change affect any new Apache threads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已从
Log::Log4perl::Level
,然后您可以执行以下操作:这是在更改记录器上的日志级别中
Log::Log4perl
文档中的部分。If you've imported the log level constants from
Log::Log4perl::Level
, then you can do things like:This is in the Changing the Log Level on a Logger section in the
Log::Log4perl
docs.对我来说这似乎有点老套,但它有效:
$Log::Log4perl::Logger::APPENDER_BY_NAME{SCREEN}->threshold($DEBUG);
为了使其更加动态,你可以传入 Appender 名称和级别的变量。
It seems kinda hacky to me, but it works:
$Log::Log4perl::Logger::APPENDER_BY_NAME{SCREEN}->threshold($DEBUG);
And to make it more dynamic, you could pass in a variable for the Appender name and level.