Log::Log4perl is a roboust logging system for Perl, but you can get started with it quite easily without the need of configuration files.


Remember, before you use this module you need to install it. e.g. using cpanm:

cpanm Log::Log4perl

Log::Log4perl example

This code:


use Log::Log4perl ();

Log::Log4perl->easy_init( {
            level    => 'INFO',
            layout   => '%d{yyyy-MM-dd HH:mm:ss} - %p - %F{1}-%L-%M - %m%n',
            # file     => ">test.log",
            # utf8     => 1,
            # category => "Bar::Twix",

my $logger = Log::Log4perl->get_logger();

$logger->debug("This is debug");
$logger->info("This is info");

Will show this log message:

2020-11-06 17:41:49 - INFO - log4perl.pl-12-main:: - This is info

You can learn a lot more about Layout patterns and the date-formatting options.