views:

316

answers:

2

I have this sub to initialize my logger:

sub initLogfiles{
    Log::Log4perl->easy_init($INFO); # We log all debug, info, warn, error and fatal messages.
        my $userlogappender = Log::Log4perl::Appender->new(
        "Log::Log4perl::Appender::File",
        filename => USERLOGFILE,
        mode     => "append",
        recreate => 1
    );
    my $userloglayout = Log::Log4perl::Layout::PatternLayout->new("%d;%m%n");
    $userlogappender->layout($userloglayout);
    $userlogger->add_appender($userlogappender);
}

I only want to have the loginfo in my logfile. How do i prevent this from logging to stdout?

+5  A: 

Log::Log4perl->easy_init() initializes the library with a ScreenAppender, that's why the log are sent to stdout.

Remove it and add the following to write all logs (debug level and above) to file:

 Log::Log4perl->get_logger()->level($DEBUG);
philippe
I dont think that is good in my code. I use the DEBUG level, so it wont do to set the threshhold to block out DEBUG. but thanks for the answer.
Allan Simonsen
I forgot to mention the easy_init() call have to be removed ; and this does not block out DEBUG. Anyway, if the additivity() does the trick, that's fine.
philippe
+5  A: 
Allan Simonsen