logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Log4perl doesn't express an error with multiple categories and a non ex: msg#00015

Subject: Re: Log4perl doesn't express an error with multiple categories and a non existent package.
On Thu, 15 Mar 2007, Daniel Lo wrote:

> I was using log4perl, when I discovered that a small mistake I had made
> did not generate any error message.  I had made a mistake in the directory
> naming.  I found that log4perl will not express an warning or error, when a
> package is declared that does not exist and there are other
> categories to choose from.

Hi Daniel,

thanks for reporting this issue! Actually, the error is in the line

    log4perl.opps                      = DEBUG, NoExist

which probably was meant to be

    log4perl.logger.opps = DEBUG, NoExist

in which case the error with the non-existing appender class would
have been reported. The way the configuration was coded,

    log4perl.opps                      = DEBUG, NoExist

it defined an undefined (but maybe future :) keyword 'opps' which was
ignored by Log4perl.

The Appender definition

    # Non Existant Appender
    log4perl.appender.NoExist          = Log::Log4perl::Appender::NoExist
    log4perl.appender.NoExist.layout   = PatternLayout
    log4perl.appender.NoExist.layout.ConversionPattern = %m%n
    );

also was ignored because no logger was actually using it.

Some day we're gonna rework the PropertyConfigurator to insist on
a fixed set of keywords, make sure that there are no dangling parts
and add better sanity checks. Really :)

-- Mike

Mike Schilli
m@xxxxxxxxxxxxxxx


>
>
>         Below is a test script that expresses this problem.
>
>
>
> Thank you for your time,
>
>
> -daniel
>
> -----------------------------------------------------------------------
>
> use warnings;
> use strict;
>
> use Log::Log4perl qw(get_logger);
> use Test::More tests => 2;
>
> # appender NoExist does not exist, and should generate some sort of error
> # message
> my $conf = qq(
> log4perl.rootLogger                = DEBUG, buffer
> log4perl.opps                      = DEBUG, NoExist
>
> # Regular Screen Appender
> log4perl.appender.buffer           = Log::Log4perl::Appender::TestBuffer
> log4perl.appender.buffer.layout    = PatternLayout
> log4perl.appender.buffer.layout.ConversionPattern = %m%n
>
> # Non Existant Appender
> log4perl.appender.NoExist          = Log::Log4perl::Appender::NoExist
> log4perl.appender.NoExist.layout   = PatternLayout
> log4perl.appender.NoExist.layout.ConversionPattern = %m%n
> );
>
> eval {
>     Log::Log4perl->init(\$conf);
> };
> ok(length($@) > 0, "This should contain an error message: $@");
>
> # no error message from: Log::Log4perl::Appender::NoExist
> diag("\$@=$@\n");
>
> my $badLogger = get_logger('opps');
> $badLogger->info('How can you log to an non-existant package?');
>
> my $buffer = Log::Log4perl::Appender::TestBuffer->by_name('buffer');
>
> is ($buffer->buffer,"","buffer is empty!");
> diag("buffer contains: " . $buffer->buffer);
>
>
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


<Prev in Thread] Current Thread [Next in Thread>