On Tue, 26 May 2009, Richard Burton wrote:

> Currently the whole script gets in to a recursive mess, the file
> logging.conf contains a simple root logger which outputs to the
> screen, I have attached it but I suspect it is not of any use.

I guess your logging.conf file looks like

     log4perl.category         = DEBUG, Screen
     log4perl.appender.Screen  = Log::Log4perl::Appender::Screen

which means that Log4perl logs to the Screen appender, which logs to
STDERR by default. But you're trapping STDERR, which is then rerouted to
Log4perl, which prints it to STDERR, which ... recursion.

Adding

     log4perl.appender.Screen.stderr = 0

to route Screen messages to STDOUT instead of STDERR breaks the cycle.

-- Mike

Mike Schilli
m...@perlmeister.com

>
>
>
> #####################################################
> #!/usr/bin/perl -w
> use strict;
>
> use Log::Log4perl qw( get_logger :levels );
> use Log::Log4perl::Level;
>
> main();
>
> sub main {
>
>    Log::Log4perl->init_once('logging.conf');
>
>    my $log = Log::Log4perl->get_logger('');
>    tie *STDERR, "Trapper";
>    $log->info("This is an informational");
>    $log->error("This is an error");
>    IgnorantModule::some_method();
>
> }
>
>
> ########################################
> package IgnorantModule;
> ########################################
>
> sub some_method {
>    print STDERR "Parbleu! An error!\n";
> }
>
> 1;
>
>
> ########################################
> package Trapper;
> ########################################
>
> use Log::Log4perl qw( get_logger :levels );
>
> sub TIEHANDLE {
>    my $class = shift;
>    bless [], $class;
> }
>
> sub PRINT {
>    my $self = shift;
>
>    $Log::Log4perl::caller_depth++;
>    get_logger()->info(@_);
>    $Log::Log4perl::caller_depth--;
> }
>
> 1;
> #####################################################
>
>
>
> Thanks
>
> Richard
>
>
>> -----Original Message-----
>> From: Mike Schilli [mailto:m...@perlmeister.com]
>> Sent: 20 May 2009 22:25
>> To: Richard Burton
>> Cc: log4perl-devel@lists.sourceforge.net
>> Subject: Re: [log4perl-devel] Log4perl and catching unhandle
>> exceptions but not using 'easy' mode
>>
>> On Wed, 20 May 2009, Richard Burton wrote:
>>
>>> I can catch this using stealth as loggers outlined in
>>>
>> http://search.cpan.org/~mschilli/Log-Log4perl/lib/Log/Log4perl
>> /FAQ.pm#So
>>>
>> me_module_prints_messages_to_STDERR._How_can_I_funnel_them_to_
>> Log::Log4p
>>> erl?
>>>
>>> but the example assumes you are using the "easy"
>> configuration method.
>>
>> Actually, this will work unmodified if you're using a
>> configuration file
>> instead.
>>
>> You're probably talking about the DEBUG(...) macro used in the code
>> example, which comes with :easy, but this is really unrelated to
>> easy_init() and can be used with init($conf_file) as well.
>> If you don't want the stealth loggers, get a logger and send
>> your debug
>> message via
>>
>>      use Log::Log4perl qw(get_logger);
>>
>>      get_logger()->debug("my debug message");
>>
>> instead.
>>
>>> The question I have is can I do a similar thing but use an external
>>> configuration file for log4perl? I have tried but failed so would
>>> appreciate any guidance?
>>
>> This should work, what was the problem/error message you encountered?
>>
>> -- Mike
>>
>> Mike Schilli
>> m...@perlmeister.com
>>
>

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to