fattahsafa has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How can I configure log4perl to print timestamp for message? currently I posted the scalar(localtime) for each message by concat. it explicitly. here is my log4perl code
use Log::Log4perl qw(get_logger :levels); our $logger = Log::Log4perl->get_logger(__PACKAGE__); $logger->level($INFO); # Appenders our $appender = Log::Log4perl::Appender->new( "Log::Dispatch::File", filename => "Automation.log", mode => "append", ); $logger->add_appender($appender); $logger->info("Logger");
Thanks, Abed.

Replies are listed 'Best First'.
Re: Configuring log4perl to print TimeStamp
by jellisii2 (Hermit) on Dec 10, 2014 at 13:32 UTC
      Thanks alot. Layout works well :) here what I added:
      my $layout = Log::Log4perl::Layout::PatternLayout->new( "%n%d - %p>%m{inden +t}"); $appender->layout($layout);
Re: Configuring log4perl to print TimeStamp
by Anonymous Monk on Dec 10, 2014 at 10:41 UTC
    change the "format" (hint search for "format" in the Log::Log4perl docs)

    FWIW the defaults have timestamps

    $ perl -e "use Log::Log4perl qw/:easy/; Log::Log4perl->easy_init($INFO +); DEBUG 1; ERROR 2; INFO 3; " 2014/12/10 02:41:57 2 2014/12/10 02:41:57 3