Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Log-Any CPAN distribution.

Maintainer(s)' notes

DO NOT FILE TICKETS HERE

Instead, file tickets on Github here → Log Any Issues.

Report information
The Basics
Id: 63284
Status: resolved
Priority: 0/
Queue: Log-Any

People
Owner: JSWARTZ [...] cpan.org
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



I would like to suggest (and code) a (small) change to Log::Any which allows the module author to choose a default logger which would log to stdout/stderr (everything below warning would go to stdout, everything above to stderr). Many of the modules I write are used by others, some of whom are not (and will never be) sophisticated users. Asking them to select a logging facility and then initializing it is too great of a burden, and frankly, will never happen. I don't worry about the sophisticated users; they can figure things out. For the non-logging users, the default logger in Log::Any is actually dangerous; they get no feed back in case of problems. If the default logger would output to stdout & stderr, at the very least they'd get something. My solution would be to add an extra tag to the import scheme ('stdio') which would do two things: * Set a default minimum log level of notice. * Use Log::Any::Adapter::STDIO instead of Log::Any::Adapter::Null. This new "adapter" would log warning and above to stderr and everything else to stdout. Log::Any::Adapter::STDIO would be included in Log::Any. A less desirable alternative would be to sub-class Log::Any (Log::Any::STDIO) and override the get_logger method to change the call from Log::Any::Adapter::Null to Log::Any::Adapter::STDIO. This approach would be prone to breakage if Log::Any::get_logger is changed. An even less desirable alternative would be to create a Log::Any::Adapter::STDIO which monkeypatched Log::Any::Adapter::Null. I'm asking (rather than coding) first so that if this concept doesn't fit within the design parameters of your package I'll not have worked in vain. (Once bitten...) Thanks for thinking about this, Diab
After thinking about this just a tad more, I think there might be a better approach which would maintain the non-logging nature of Log::Any as well allow me to provide a default logging which can still be easily overridden. Instead of hardwiring Log::Any::Adapter::Null, allow the caller to specify another adapter which will be treated as the "Null adapter", e.g. use Log::Any ( default => STDIO, '$log' ); Internal to Log::Any this would default to the current Null adapter.
Subject: Patch to implement "default" import tag
That last idea was very quick to code, so here it is, as a patch against Log::Any 0.11
Subject: Log-Any-0.11.patch
# This is a patch for Log-Any-0.11.orig to update it to Log-Any-0.11 # # To apply this patch: # STEP 1: Chdir to the source directory. # STEP 2: Run the 'applypatch' program with this patch file as input. # # If you do not have 'applypatch', it is part of the 'makepatch' package # that you can fetch from the Comprehensive Perl Archive Network: # http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz # In the above URL, 'x' should be 2 or higher. # # To apply this patch without the use of 'applypatch': # STEP 1: Chdir to the source directory. # STEP 2: Run the 'patch' program with this file as input. # #### End of Preamble #### #### Patch data follows #### diff -c 'Log-Any-0.11.orig/lib/Log/Any.pm' 'Log-Any-0.11/lib/Log/Any.pm' Index: ./lib/Log/Any.pm *** ./lib/Log/Any.pm Fri Feb 12 07:46:09 2010 --- ./lib/Log/Any.pm Tue Nov 23 12:14:47 2010 *************** *** 4,13 **** our $VERSION = '0.11'; - # Require rather than use, because it depends on subroutines defined below - # - require Log::Any::Adapter::Null; - # This is accessed in Log::Any::Adapter::Manager::new # our %NullAdapters; --- 4,9 ---- *************** *** 24,41 **** my $class = shift; my $caller = shift; # Parse parameters passed to 'use Log::Any' # my @vars; ! foreach my $param (@_) { if ( $param eq '$log' ) { ! my $log = $class->get_logger( category => $caller ); no strict 'refs'; my $varname = "$caller\::log"; *$varname = \$log; } else { ! die "invalid import '$param' - valid imports are '\$log'"; } } } --- 20,53 ---- my $class = shift; my $caller = shift; + my $def_adapter; + # Parse parameters passed to 'use Log::Any' # + my $skip = 0; my @vars; ! while( @_ ) { ! ! my $param = shift( @_ ); ! if ( $param eq '$log' ) { ! my $log = $class->get_logger( category => $caller, ! def_adapter => $def_adapter ! ); no strict 'refs'; my $varname = "$caller\::log"; *$varname = \$log; } + elsif ( $param eq 'default' ) { + + die "import 'default' requires an argument" + unless @_; + + $def_adapter = 'Log::Any::Adapter::' . shift( @_ ); + + } else { ! die "invalid import '$param' - valid imports are '\$log' and 'default'"; } } } *************** *** 47,61 **** if ( !defined($category) ) { $category = caller(); } if ($Log::Any::Adapter::Initialized) { return Log::Any::Adapter->get_logger( $category, %params ); } else { # Record each null adapter that we return, so that we can override # them later if and when Log::Any::Adapter->set is called # ! $NullAdapters{$category} ||= Log::Any::Adapter::Null->new(); return $NullAdapters{$category}; } } --- 59,80 ---- if ( !defined($category) ) { $category = caller(); } + + my $def_adapter = delete( $params{'def_adapter'}) || 'Log::Any::Adapter::Null'; + if ($Log::Any::Adapter::Initialized) { return Log::Any::Adapter->get_logger( $category, %params ); } else { + # Require rather than use, because it depends on subroutines defined below + # + eval "require $def_adapter;" or die $@; + # Record each null adapter that we return, so that we can override # them later if and when Log::Any::Adapter->set is called # ! $NullAdapters{$category} ||= $def_adapter->new(); return $NullAdapters{$category}; } } #### End of Patch data #### #### ApplyPatch data follows #### # Data version : 1.0 # Date generated : Tue Nov 23 12:19:42 2010 # Generated by : makepatch 2.04 # Recurse directories : Yes # Excluded files : (\A|/).*\~\Z # (\A|/).*\.a\Z # (\A|/).*\.bak\Z # (\A|/).*\.BAK\Z # (\A|/).*\.elc\Z # (\A|/).*\.exe\Z # (\A|/).*\.gz\Z # (\A|/).*\.ln\Z # (\A|/).*\.o\Z # (\A|/).*\.obj\Z # (\A|/).*\.olb\Z # (\A|/).*\.old\Z # (\A|/).*\.orig\Z # (\A|/).*\.rej\Z # (\A|/).*\.so\Z # (\A|/).*\.Z\Z # (\A|/)\.del\-.*\Z # (\A|/)\.make\.state\Z # (\A|/)\.nse_depinfo\Z # (\A|/)core\Z # (\A|/)tags\Z # (\A|/)TAGS\Z # p 'lib/Log/Any.pm' 10603 1290532487 0100644 #### End of ApplyPatch data #### #### End of Patch kit [created: Tue Nov 23 12:19:42 2010] #### #### Patch checksum: 146 4317 22006 #### #### Checksum: 164 5008 13471 ####
Thanks - I would like to make things easier for casual users. I'll look at this shortly.
I've taken over maintenance and implemented a version of this in my repository.
On Wed Aug 21 21:59:44 2013, DAGOLDEN wrote: Show quoted text
> I've taken over maintenance and implemented a version of this in my > repository.
Thanks!
This is implemented in Log-Any-1.XX now on CPAN