From: David C. <dpc...@ho...> - 2013-11-05 07:18:37
|
log4perl-devel: I am working on a module that incorporates stealth logging. I've used logwarn() in place of warn() throughout. When I enable a logger in a script that use's the module, I see warning messages both on the terminal and in the log destination. But, when there is no logger enabled, I don't see any warning messages on the terminal. I was expecting logwarn() would always output the warning message to the terminal, and additionally output the warning message to the log destination if logging is enabled. Apparently, not. As an aside, logdie() appears to work as expected. I see that Log::Log4perl is now version 1.42 on CPAN. I'm on Debian Stable (Wheezy), which has version 1.29. I'd rather not upgrade via 'cpan', as I've found that circumventing Apt and the Debian release process leads to problems. I don't see liblog-log4perl-perl on Debian Backports. Any suggestions? TIA, David 2013-11-04 23:08:03 dpchrist@p43200 ~/sandbox/perl $ cat Log-Log4perl-logwarn.pl #!/usr/bin/perl use strict; use warnings; use Log::Log4perl qw(:easy); warn "first warning"; my $logger = Log::Log4perl->get_logger(); $logger->logwarn("second warning"); Log::Log4perl->easy_init($WARN); warn "third warning"; $logger->logwarn("fourth warning"); 2013-11-04 23:08:08 dpchrist@p43200 ~/sandbox/perl $ perl Log-Log4perl-logwarn.pl first warning at Log-Log4perl-logwarn.pl line 5. third warning at Log-Log4perl-logwarn.pl line 9. 2013/11/04 23:08:12 fourth warning fourth warning at Log-Log4perl-logwarn.pl line 10 2013-11-04 23:08:12 dpchrist@p43200 ~/sandbox/perl $ cat Log-Log4perl-logdie.pl #!/usr/bin/perl use strict; use warnings; use Log::Log4perl qw(:easy); my $logger = Log::Log4perl->get_logger(); $logger->logdie("bye"); 2013-11-04 23:08:18 dpchrist@p43200 ~/sandbox/perl $ perl Log-Log4perl-logdie.pl bye at Log-Log4perl-logdie.pl line 6 2013-11-04 23:08:23 dpchrist@p43200 ~/sandbox/perl $ cat Log-Log4perl-logdie2.pl #!/usr/bin/perl use strict; use warnings; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($WARN); my $logger = Log::Log4perl->get_logger(); $logger->logdie("bye"); 2013-11-04 23:08:31 dpchrist@p43200 ~/sandbox/perl $ perl Log-Log4perl-logdie2.pl 2013/11/04 23:08:34 bye bye at Log-Log4perl-logdie2.pl line 7 2013-11-04 23:08:34 dpchrist@p43200 ~/sandbox/perl $ perl -MLog::Log4perl -e 'print $Log::Log4perl::VERSION, "\n"' 1.29 2013-11-04 23:08:45 dpchrist@p43200 ~/sandbox/perl $ perl --version This is perl 5, version 14, subversion 2 (v5.14.2) built for i486-linux-gnu-thread-multi-64int (with 88 registered patches, see perl -V for more detail) Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. 2013-11-04 23:08:55 dpchrist@p43200 ~/sandbox/perl $ cat /etc/debian_version 7.2 |
From: David C. <dpc...@ho...> - 2013-11-05 18:02:45
|
On 11/04/2013 11:18 PM, David Christensen wrote: > I was expecting logwarn() would always output the > warning message to the terminal, and additionally output the warning > message to the log destination if logging is enabled. I found a work-around -- write a wrapper that calls warn() and $logger->warn() instead. HTH, David 2013-11-05 10:01:04 dpchrist@p43200 ~/sandbox/perl $ cat Log-Log4perl-warn.pl #!/usr/bin/perl use strict; use warnings; use Log::Log4perl qw(:easy); sub mylogwarn { my $logger = Log::Log4perl->get_logger(); warn @_; $logger->warn(@_); } mylogwarn "first warning"; Log::Log4perl->easy_init($WARN); mylogwarn "second warning"; 2013-11-05 10:01:10 dpchrist@p43200 ~/sandbox/perl $ perl Log-Log4perl-warn.pl first warning at Log-Log4perl-warn.pl line 7. second warning at Log-Log4perl-warn.pl line 7. 2013/11/05 10:01:13 second warning |
From: Mike S. <m...@pe...> - 2013-11-06 02:38:08
|
On Mon, 4 Nov 2013, David Christensen wrote: > I was expecting logwarn() would always output the warning message to > the terminal, and additionally output the warning message to the log > destination if logging is enabled. Apparently, not. This was fixed in Log4perl 1.35: https://github.com/mschilli/log4perl/commit/7d7fbbb45254d6c903f5b3cb91d7 > I see that Log::Log4perl is now version 1.42 on CPAN. I'm on Debian > Stable (Wheezy), which has version 1.29. I'd rather not upgrade via > 'cpan', as I've found that circumventing Apt and the Debian release > process leads to problems. I wouldn't do it in the main root to avoid stepping on the package manager's files, but if you maintain your own local directory via local::lib that should work just fine. Ideally, I wouldn't use the system perl for applications in the first place, but install a separate one via perlbrew et al. > I don't see liblog-log4perl-perl on Debian Backports. Later versions of Debian seem to have more up-to-date versions of Log4perl: http://packages.debian.org/sid/liblog-log4perl-perl -- -- Mike Mike Schilli m...@pe... > > Any suggestions? > > TIA, > > David > > > > 2013-11-04 23:08:03 dpchrist@p43200 ~/sandbox/perl > $ cat Log-Log4perl-logwarn.pl > #!/usr/bin/perl > use strict; > use warnings; > use Log::Log4perl qw(:easy); > warn "first warning"; > my $logger = Log::Log4perl->get_logger(); > $logger->logwarn("second warning"); > Log::Log4perl->easy_init($WARN); > warn "third warning"; > $logger->logwarn("fourth warning"); > > 2013-11-04 23:08:08 dpchrist@p43200 ~/sandbox/perl > $ perl Log-Log4perl-logwarn.pl > first warning at Log-Log4perl-logwarn.pl line 5. > third warning at Log-Log4perl-logwarn.pl line 9. > 2013/11/04 23:08:12 fourth warning > fourth warning at Log-Log4perl-logwarn.pl line 10 > > 2013-11-04 23:08:12 dpchrist@p43200 ~/sandbox/perl > $ cat Log-Log4perl-logdie.pl > #!/usr/bin/perl > use strict; > use warnings; > use Log::Log4perl qw(:easy); > my $logger = Log::Log4perl->get_logger(); > $logger->logdie("bye"); > > 2013-11-04 23:08:18 dpchrist@p43200 ~/sandbox/perl > $ perl Log-Log4perl-logdie.pl > bye at Log-Log4perl-logdie.pl line 6 > > 2013-11-04 23:08:23 dpchrist@p43200 ~/sandbox/perl > $ cat Log-Log4perl-logdie2.pl > #!/usr/bin/perl > use strict; > use warnings; > use Log::Log4perl qw(:easy); > Log::Log4perl->easy_init($WARN); > my $logger = Log::Log4perl->get_logger(); > $logger->logdie("bye"); > > 2013-11-04 23:08:31 dpchrist@p43200 ~/sandbox/perl > $ perl Log-Log4perl-logdie2.pl > 2013/11/04 23:08:34 bye > bye at Log-Log4perl-logdie2.pl line 7 > > 2013-11-04 23:08:34 dpchrist@p43200 ~/sandbox/perl > $ perl -MLog::Log4perl -e 'print $Log::Log4perl::VERSION, "\n"' > 1.29 > > 2013-11-04 23:08:45 dpchrist@p43200 ~/sandbox/perl > $ perl --version > > This is perl 5, version 14, subversion 2 (v5.14.2) built for > i486-linux-gnu-thread-multi-64int > (with 88 registered patches, see perl -V for more detail) > > Copyright 1987-2011, Larry Wall > > Perl may be copied only under the terms of either the Artistic License > or the > GNU General Public License, which may be found in the Perl 5 source kit. > > Complete documentation for Perl, including FAQ lists, should be found on > this system using "man perl" or "perldoc perl". If you have access to the > Internet, point your browser at http://www.perl.org/, the Perl Home Page. > > > 2013-11-04 23:08:55 dpchrist@p43200 ~/sandbox/perl > $ cat /etc/debian_version > 7.2 > > ------------------------------------------------------------------------------ > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > |
From: David C. <dpc...@ho...> - 2013-11-06 02:55:50
|
On 11/05/2013 06:17 PM, Mike Schilli wrote: Thanks for the reply, and thanks for Log::Log4perl. :-) > This was fixed in Log4perl 1.35: I suspected as much. > I wouldn't do it in the main root to avoid stepping on the package > manager's files, but if you maintain your own local directory via > local::lib that should work just fine. I use local::lib for my code, but try to use the distribution package manager for CPAN modules. If/when I must have a CPAN module that isn't packaged, I'll put it in local::lib. > Ideally, I wouldn't use the > system perl for applications in the first place, but install a separate > one via perlbrew et al. ... > Later versions of Debian seem to have more up-to-date versions of > Log4perl: I'm working on modules/ scripts to automate system configuration/ administration of Debian 7 machines. So, I'm trying to write Perl code that works with Debian 7 OOTB as much as possible. I'll go with my wrapper work-around for now. David |