+# add example for Log::Dispatchouli
+# make wrapper for Log::Log4perl that fixes callstack:
+# < mst> sub debug { local $Log::Log4perl::caller_depth =
+# $Log::Log4perl::caller_depth + 3; shift->{l4p}->debug(@_) }
+#
+# default logger stuff
+# < mst> there are two cases
+# < mst> (1) application code: expects an app logger to be set and fuck you if it
+# isn't
+# < mst> (i.e. die screaming if it gets called without a logger setup)
+# < frew> sure
+# < mst> (2) library code: uses an app logger IF exists, but if not, needs to do ...
+# something sensible
+# < mst> but doesn't want to affect the rest of the world doing so
+# < frew> sounds like library code wants default_logger which is a packageish logger?
+#
+# make basic warn logger
+
+
package Log::Contextual;
use strict;
}
our $Get_Logger;
+our %Default_Logger;
+
+sub _get_logger($) {
+ my $package = shift;
+ (
+ $Get_Logger ||
+ $Default_Logger{$package} ||
+ die q( no logger set! you can't try to log something without a logger! )
+ )->();
+}
sub set_logger {
my $logger = $_[0];
unless blessed($logger);
$logger = do { my $l = $logger; sub { $l } }
}
+
+ warn 'set_logger (or -logger) called more than once! This is a bad idea!'
+ if $Get_Logger;
$Get_Logger = $logger;
}
sub log_trace (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->trace($code->(@_))
if $log->is_trace;
}
sub log_debug (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->debug($code->(@_))
if $log->is_debug;
}
sub log_info (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->info($code->(@_))
if $log->is_info;
}
sub log_warn (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->warn($code->(@_))
if $log->is_warn;
}
sub log_error (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->error($code->(@_))
if $log->is_error;
}
sub log_fatal (&@) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
$log->fatal($code->(@_))
if $log->is_fatal;
sub logS_trace (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->trace($code->($value))
}
sub logS_debug (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->debug($code->($value))
}
sub logS_info (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->info($code->($value))
}
sub logS_warn (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->warn($code->($value))
}
sub logS_error (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->error($code->($value))
}
sub logS_fatal (&$) {
- my $log = $Get_Logger->();
+ my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
$log->fatal($code->($value))