简体   繁体   English

如何在命令行上设置Log4perl日志级别?

[英]How to set Log4perl log level on the command line?

Is it possible to set the log level globally for Log4perl by passing a command line flag or setting an environment variable (and not changing the original logging setup)? 是否可以通过传递命令行标志或设置环境变量(而不更改原始日志记录设置)来全局设置Log4perl的日志级别? The documentation and FAQ don't seem to mention any way to do this. 文档FAQ似乎没有提及执行此操作的任何方法。

You may use somthing like this: 您可以这样使用:

Log::Log4perl->get_logger()->level(
    Log::Log4perl::Level::to_priority($ENV{APP_LOG_LEVEL})
);

and run script: 并运行脚本:

APP_LOG_LEVEL=DEBUG perl app.pl

If you use the configuration file syntax to define your appenders (note that you don't have to place this into a real file; you can also have the configuration definition inside your program), you already have environment variable substitution out of the box. 如果您使用配置文件语法定义附加程序(请注意,您不必将其放置到真实文件中;您也可以在程序内部使用配置定义),那么您已经可以使用环境变量替换。 See the section named "Variable Substitution" in the Log4Perl documentation . 请参阅Log4Perl文档中名为“变量替换”的部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM