Perl 的 Log::Log4perl 的日志级别可以在不更新配置的情况下动态更改吗?

发布于 2024-11-05 21:37:11 字数 182 浏览 1 评论 0原文

我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-11-12 21:37:11

如果您已从 Log::Log4perl::Level,然后您可以执行以下操作:

$logger->level($ERROR); # one of DEBUG, INFO, WARN, ERROR, FATAL

$logger->more_logging($delta); # Increase log level by $delta levels,
                               # a positive integer

$logger->less_logging($delta); # Decrease log level by $delta levels.

这是在更改记录器上的日志级别中Log::Log4perl 文档中的部分。

If you've imported the log level constants from Log::Log4perl::Level, then you can do things like:

$logger->level($ERROR); # one of DEBUG, INFO, WARN, ERROR, FATAL

$logger->more_logging($delta); # Increase log level by $delta levels,
                               # a positive integer

$logger->less_logging($delta); # Decrease log level by $delta levels.

This is in the Changing the Log Level on a Logger section in the Log::Log4perl docs.

百善笑为先 2024-11-12 21:37:11

对我来说这似乎有点老套,但它有效:

$Log::Log4perl::Logger::APPENDER_BY_NAME{SCREEN}->threshold($DEBUG);

为了使其更加动态,你可以传入 Appender 名称和级别的变量。

%LOG4PERL_LEVELS =
(
  OFF   =>$OFF,
  FATAL =>$FATAL,
  ERROR =>$ERROR,
  WARN  =>$WARN,
  INFO  =>$INFO,
  DEBUG =>$DEBUG,
  TRACE =>$TRACE,
  ALL   =>$ALL
);

$Log::Log4perl::Logger::APPENDER_BY_NAME{$appender_name}->threshold($LOG4PERL_LEVELS{$new_level});

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.

%LOG4PERL_LEVELS =
(
  OFF   =>$OFF,
  FATAL =>$FATAL,
  ERROR =>$ERROR,
  WARN  =>$WARN,
  INFO  =>$INFO,
  DEBUG =>$DEBUG,
  TRACE =>$TRACE,
  ALL   =>$ALL
);

$Log::Log4perl::Logger::APPENDER_BY_NAME{$appender_name}->threshold($LOG4PERL_LEVELS{$new_level});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文