Perl Logging Guide: Track & Record Logs
You can use the built-in logging module Log::Log4perl in Perl to record and track logs. Here is a simple example code:
use Log::Log4perl;
# 配置日志输出
Log::Log4perl->init(\ q{
log4perl.logger=DEBUG, Screen
log4perl.appender.Screen=Log::Log4perl::Appender::Screen
log4perl.appender.Screen.layout=Log::Log4perl::Layout::SimpleLayout
});
# 获取日志对象
my $logger = Log::Log4perl->get_logger();
# 记录日志
$logger->debug("This is a debug message");
$logger->info("This is an info message");
$logger->warn("This is a warning message");
$logger->error("This is an error message");
$logger->fatal("This is a fatal message");
After running the code, the logs will be displayed on the screen and the log output level and format can be adjusted according to configuration. You can also output the logs to a file or other locations by referring to the documentation of Log::Log4perl.