Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to pick an appender selectively in Log::Log4perl

by hellosarathy (Novice)
on Feb 11, 2016 at 13:31 UTC ( #1154953=perlquestion: print w/replies, xml ) Need Help??
hellosarathy has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a Log::Log4perl logger configured which writes to STDOUT, SYSLOG and Logfile, like:

my %loggerConfig = ( "log4perl.category.default_logger" => "INFO, Stdout, SYSLOG, Logfile",
which writes to STDOUT, SYSLOG and Logfile. Few messages I need to write ONLY to the log file and NOT to syslog and STDOUT. How can this be done?

Thanks.

Replies are listed 'Best First'.
Re: How to pick an appender selectively in Log::Log4perl
by Arunbear (Parson) on Feb 11, 2016 at 17:12 UTC
    Create a separate category that only writes to Logfile
    my %loggerConfig = ( "log4perl.category.default_logger" => "INFO, Stdout, SYSLOG, Logfile +", "log4perl.category.file.only" => "INFO, Logfile", );
    Then to use it:
    my $log = Log::Log4perl->get_logger("file.only"); $log->info('whatever');
      Thanks.
Re: How to pick an appender selectively in Log::Log4perl
by crusty_collins (Friar) on Feb 11, 2016 at 16:59 UTC
    You can select what you want. I would do it like this.
    my $log_conf = qq( log4perl.rootLogger = DEBUG, LOG log4perl.appender.LOG = Log::Log4perl::Appender: +:File log4perl.appender.LOG.filename = $ref->{config}->{Log} log4perl.appender.LOG.mode = append log4perl.appender.LOG.layout = Log::Log4perl::Layout::P +atternLayout log4perl.appender.LOG.layout.ConversionPattern = %d %p %m %n );
    "We can't all be happy, we can't all be rich, we can't all be lucky and it would be so much less fun if we were. There must be the dark background to show up the bright colours." Jean Rhys (1890-1979)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1154953]
Approved by GotToBTru
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-12-13 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (361 votes). Check out past polls.

    Notices?