ChangeLog for Log-Contextual
+ - merge unpushed 0.004300 into master (frew--, Tyler Riddle++)
+
0.005000_02 2013-01-15
- add missing changelog entry (derp)
something like that) and changing their logger. See the new
Log::Contextual::Role::Router for more information
+0.004300 2012-10-03
+ - add a way to set default import tags
+
0.004202 2012-08-04
- correct the caller_level passed into coderef, and document "both" uses of
caller_level
}
}
+sub default_import {
+ my ($class) = shift;
+
+ die 'Log::Contextual does not have a default import list';
+
+ ()
+}
+
sub arg_logger { $_[1] }
sub arg_levels { $_[1] || [qw(debug trace warn info error fatal)] }
sub arg_package_logger { $_[1] }
arguments => $spec->argument_info
);
- die 'Log::Contextual does not have a default import list'
+ my @tags = $class->default_import($spec)
if $spec->config->{default};
+ for (@tags) {
+ die "only tags are supported for defaults at this time"
+ unless $_ =~ /^:(.*)$/;
+
+ $spec->config->{$1} = 1;
+ }
+
$router->before_import(%router_args);
if ($exports->{'&set_logger'}) {
sub arg_default_logger { $_[1] || Log::Log4perl->get_logger }
sub arg_levels { [qw(debug trace warn info error fatal custom_level)] }
+ sub default_import { ':log' }
# or maybe instead of default_logger
sub arg_package_logger { $_[1] }
Your C<arg_default_logger> method will get C<$foo> and your C<arg_levels>
will get C<[qw(bar baz biff)]>;
+Additionally, the C<default_import> method is what happens if a user tries to
+use your subclass with no arguments. The default just dies, but if you'd like
+to change the default to import a tag merely return the tags you'd like to
+import. So the following will all work:
+
+ sub default_import { ':log' }
+
+ sub default_import { ':dlog' }
+
+ sub default_import { qw(:dlog :log ) }
+
=head1 FUNCTIONS
=head2 set_logger
--- /dev/null
+use strict;
+use warnings;
+
+use lib 't/lib';
+
+use DefaultImportLogger;
+use Test::More qw(no_plan);
+
+my @levels = qw(lol wut zomg);
+
+VANILLA: {
+ for (@levels) {
+ main->can("log_$_")->(sub { 'fiSMBoC' });
+ is( $DumbLogger2::var, "[$_] fiSMBoC\n", "$_ works");
+
+ my @vars = main->can("log_$_")->(sub { 'fiSMBoC: ' . $_[1] }, qw{foo bar baz});
+ is( $DumbLogger2::var, "[$_] fiSMBoC: bar\n", "log_$_ works with input");
+ ok( eq_array(\@vars, [qw{foo bar baz}]), "log_$_ passes data through correctly");
+
+ my $val = main->can("logS_$_")->(sub { 'fiSMBoC: ' . $_[0] }, 'foo');
+ is( $DumbLogger2::var, "[$_] fiSMBoC: foo\n", "logS_$_ works with input");
+ is( $val, 'foo', "logS_$_ passes data through correctly");
+ }
+}
+
--- /dev/null
+package DefaultImportLogger;
+
+use base 'Log::Contextual';
+use Log::Contextual::SimpleLogger;
+
+my $logger = DumbLogger2->new;
+
+sub default_import { ':log' }
+sub arg_levels { $_[1] || [qw(lol wut zomg)] }
+sub arg_logger { $_[1] || $logger }
+
+package DumbLogger2;
+
+our $var;
+sub new { bless {}, 'DumbLogger2' }
+sub is_wut { 1 }
+sub wut { $var = "[wut] $_[1]\n" }
+sub is_lol { 1 }
+sub lol { $var = "[lol] $_[1]\n" }
+sub is_zomg { 1 }
+sub zomg { $var = "[zomg] $_[1]\n" }
+
+1;