简体   繁体   中英

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)? The documentation and FAQ don't seem to mention any way to do this.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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