Re: [log4perl-devel] log4perl appenders with warp_message=0
On Tue, 13 May 2008, Erskine, Thomas (IT) wrote: > While warp_message is indeed an appender setting, if you have two > appenders, one with warp_message=0 and one without, then you'll get > the mess I got: the one with will work fine and will have access to > extra args separately, but the one without will mash the args into > a single message. > > Perhaps I ought to have said that, while it's possible to have appenders > with warp_message=0 and those without in the same setup, it's not > _useful_ as the result will be a mess. It's a dilemma: We're hiding probes in the code that should work for all appenders, and yet some appenders interpret them differently. Note that the Log4perl configuration is supposed to be independent of the code. Any person, even those unfamiliar with your code, should be able to define a Log4perl config file from scratch to run it with. I'm admitting that this is a stretch (and what L4p does deviates from the strict Log4j standard) but we've found it useful for database appenders, for example. I'll be the first to admit, though, that this isn't a 100% clean solution. I guess you could find arguments either way, but I feel that mashing arguments as a default is reasonable and provides predictable results. > On a completely different topic, while making a Null appender (which > discards everything), I noticed that it doesn't seem possible to make > the initializer shut up about it not having a layout. Even though > I added in code to the new to cause it to inflict the NoopLayout to > itself. It just seemed that I shouldn't have to provide configuration > for a Null appender, since it isn't doing anything. Instead, I have > to say: > log4perl.xxx.appender=Null > log4perl.xxx.layout=NoopLayout > log4perl.xxx.warp_message=0 > I understand that you're just (properly) checking that people haven't > made a stupid mistake in forgetting the layout. Exactly, catching stupid errors has precedence over making slick code short. :) -- 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/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] Understanding the config
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/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
Re: [log4perl-devel] setting defaults for appenders
On Tue, 13 May 2008, Jonathan Swartz wrote: > In the meantime, I might try to do this myself by creating my own > Appender subclass: > > # My::Log4perl::Appender::File defaults to my preferred layout > and layout.ConversionPattern > log4perl.appender.file1 = My::Log4perl::Appender::File > log4perl.appender.file2 = My::Log4perl::Appender::File > > Do you have a vague idea of how I might approach this? Or is it too > diffiicult, and I should just suck up the repetition until the > inheritance feature? :) Appenders and layouts are different concepts, so I wouldn't put them into the same class. I'd probably just use a template enginge like the template toolkit, define a Log4perl config file in a meta format and have the template engine expand everything before Log4perl reads in the configuration. -- 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/vse012070mrt/direct/01/ ___ log4perl-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/log4perl-devel
