On Tue, 13 May 2008, Bill Moseley wrote:

> I inherited an existing Log4perl configuration, and I think I'm
> missing some key point.

Wow, I had no idea we're so old that you could inherit a log4perl
configuration, but I guess time goes by :).

> The config file starts out:
> log4perl.rootLogger = INFO, syslogAppender, screenAppender
> >From the examples I've seen and the ::Config docs I thought it should
> be "log4perl.logger" not "log4perl.rootLogger".

log4perl.logger with no category and log4perl.rootLogger are actually
synonymous.

log4perl.logger.foo.bar (with category foo.bar) needs to be 'logger',
not rootLogger, obviously.

> In ::Config it also give these examples:
>     log4perl.logger.Bar.Twix = DEBUG, A1
>     log4perl.category.Bar.Twix      = WARN, Screen
> Why is it "category" instead of "logger"?

That's an issue we inherited from Log4j. They started out naming
categories "categories", then all of a sudden they called them loggers.
I personally prefer the term 'category'. So, 'category' and 'logger'
in a log4perl config file are synonymous.

Yeah, confusing, I know :).

> Finally, for a config like this in the example, what would
> be the perl code equivalent if not using a config file?
>
>     log4perl.logger.Bar.Twix = DEBUG, A1
>     log4perl.appender.A1=Log::Log4perl::Appender::File
>     log4perl.appender.A1.filename=test.log
>     log4perl.appender.A1.mode=append
>     log4perl.appender.A1.layout = \
>         Log::Log4perl::Layout::PatternLayout
>     log4perl.appender.A1.layout.ConversionPattern = %d %m %n
>
>
> Like this?
>
>     use Log::Log4perl qw(:levels);
>     use Log::Log4perl::Appender::File;
>
>     my $appender = Log::Log4perl::Appender::File->new(
>       filename  => 'test.log',
>       mode      => 'append',
>       layout    => Log::Log4perl::Layout::PatternLayout->new( '%d %m %n'),
>     );
>
>     my $logger = Log::Log4perl->get_logger( 'Bar::Twix' );
>
>     $logger->level( $DEBUG );
>     $logger->add_appender( $appender );

You need to call the appender's layout() method to set the layout, other
than that, the code above looks ok to me at first glance. It's fairly
unusual to use Perl code to init Log4perl, most of the time people
either use easy_init() or init($conf_file).

-- Mike

Mike Schilli
[EMAIL PROTECTED]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to