From: Richard B. <ri...@at...> - 2009-05-20 16:52:39
|
Hi all I am trying to capture unhandled exceptions that are sent to STDERR, e.g. for example the following could would give such an error my $test = 'foo'; if ($test == 55) { } gives Argument "foo" isn't numeric in numeric eq (==) at.... 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. 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? Thanks Richard |
From: Mike S. <m...@pe...> - 2009-05-20 21:25:57
|
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...@pe... |
From: Richard B. <ri...@at...> - 2009-05-21 11:35:42
|
Hi Mike All I am trying to do is to write unhandled exceptions to file, e.g. I am using a package off CPAN that explodes in a horrible way but as the exception is internal to the package I may not have the relevant error checking in place to catch the error? It is more of a general question so that I can build it in to my code; I don't have a specific example? Does that help? Richard > -----Original Message----- > From: Mike Schilli [mailto:m...@pe...] > Sent: 20 May 2009 22:25 > To: Richard Burton > Cc: log...@li... > 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...@pe... > |
From: Mike S. <m...@pe...> - 2009-05-22 03:35:32
|
On Thu, 21 May 2009, Richard Burton wrote: > It is more of a general question so that I can build it in to my code; > I don't have a specific example? Maybe I misunderstood, but you said "I have tried but failed", and from what I saw, you're doing everything correctly. -- Mike Mike Schilli m...@pe... > > Does that help? > > Richard > >> -----Original Message----- >> From: Mike Schilli [mailto:m...@pe...] >> Sent: 20 May 2009 22:25 >> To: Richard Burton >> Cc: log...@li... >> 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...@pe... >> > > ------------------------------------------------------------------------------ > 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 asthey present alongside digital heavyweights like Barbarian > Group, R/GA, & Big Spaceship. http://www.creativitycat.com > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > |
From: Richard B. <ri...@at...> - 2009-05-26 16:52:09
Attachments:
logging.conf
|
Hi Mike Firstly thanks for the help your help so far.. I think I am almost seeing the light, my only question now is actually outputting the log text, below is my test script, could you outline what I should be putting for the line :- get_logger()->info(@_) in the PRINT method of package Trapper; 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. ##################################################### #!/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...@pe...] > Sent: 20 May 2009 22:25 > To: Richard Burton > Cc: log...@li... > 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...@pe... > |
From: Mike S. <m...@pe...> - 2009-05-27 14:17:41
|
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...@pe... > > > > ##################################################### > #!/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...@pe...] >> Sent: 20 May 2009 22:25 >> To: Richard Burton >> Cc: log...@li... >> 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...@pe... >> > |
From: Robert J. <yad...@sn...> - 2009-05-20 21:51:58
|
Richard Burton richard-at-atomwide.com |log4perl_sourceforge| wrote: > Hi all > > I am trying to capture unhandled exceptions that are sent to STDERR, > e.g. for example the following could would give such an error [snip] > > 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. > > 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? Here's what I did: 1. Make a file "trapper.pl". It's basically the same as the example, except the Log4perl init, which uses a config file (in this case, with a SIGHUP to re-read it): ######################################## package Trapper; ######################################## use Log::Log4perl qw(get_logger :levels); Log::Log4perl->init_and_watch("../log4perl.conf",'HUP'); my $logger = get_logger("program.category"); sub TIEHANDLE { ... [etc] 2. In my perl program: require "trapper.pl"; tie (*STDERR, 'Trapper'); HTH, Rob |
From: Mike S. <m...@pe...> - 2009-05-21 07:16:07
|
On Wed, 20 May 2009, Robert Jacobson wrote: > Here's what I did: 1. Make a file "trapper.pl". It's basically the > same as the example, except the Log4perl init, which uses a config > file (in this case, with a SIGHUP to re-read it): Looks ok at first glance, doesn't it produce the expected output? Please post the complete (runnable) code to make it easier to diagnose the problem. -- Mike Mike Schilli m...@pe... > > ######################################## > package Trapper; > ######################################## > > use Log::Log4perl qw(get_logger :levels); > > Log::Log4perl->init_and_watch("../log4perl.conf",'HUP'); > my $logger = get_logger("program.category"); > > > sub TIEHANDLE { > ... [etc] > > 2. In my perl program: > require "trapper.pl"; > tie (*STDERR, 'Trapper'); > > > HTH, > Rob > > > > > ------------------------------------------------------------------------------ > 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 asthey present alongside digital heavyweights like Barbarian > Group, R/GA, & Big Spaceship. http://www.creativitycat.com > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > |