On Wed, 17 Sep 2008, William Reardon wrote:

> Using log4perl, is it possible to have multiple log files/Logfile
> appenders?  E.g., most logging goes to 'my_application.log', but with
> something like 'get_logger( "SPECIAL" )' I can route messages to
> 'special.log'?

Sure, that's a common case: Just define another category and have its
messages routed to a second appender:

use Log::Log4perl qw(:easy);

     my $conf = q{
     log4perl.logger.foo = DEBUG, FooAppender
     log4perl.logger.bar = DEBUG, BarAppender

     log4perl.appender.FooAppender = Log::Log4perl::Appender::File
     log4perl.appender.FooAppender.filename = foo.log
     log4perl.appender.FooAppender.layout = SimpleLayout

     log4perl.appender.BarAppender = Log::Log4perl::Appender::File
     log4perl.appender.BarAppender.filename = bar.log
     log4perl.appender.BarAppender.layout = SimpleLayout
     };

     Log::Log4perl->init( \$conf );

     get_logger("foo")->debug("foo!");
     get_logger("bar")->debug("bar!");

gets you

     $ cat foo.log
     DEBUG - foo!

     $ cat bar.log
     DEBUG - bar!

-- Mike

Mike Schilli
[EMAIL PROTECTED]

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to