use strict;
use warnings;
-use lib 't/lib';
-use VarLogger;
+use Log::Contextual::SimpleLogger;
use Test::More 'no_plan';
my $var_log;
+my $var;
+
+BEGIN {
+ $var_log = Log::Contextual::SimpleLogger->new({
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var = shift }
+ })
+}
-BEGIN { $var_log = VarLogger->new }
use Log::Contextual qw{:dlog}, -logger => $var_log;
{
my @foo = Dlog_trace { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_trace passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_trace is correct');
-tLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_trace is correct');
+[trace] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_trace { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_trace passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_trace is correct');
-tLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_trace is correct');
+[trace] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_debug { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_debug passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_debug is correct');
-dLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_debug is correct');
+[debug] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_debug { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_debug passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_debug is correct');
-dLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_debug is correct');
+[debug] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_info { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_info passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_info is correct');
-iLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_info is correct');
+[info] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_info { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_info passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_info is correct');
-iLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_info is correct');
+[info] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_warn { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_warn passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_warn is correct');
-wLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_warn is correct');
+[warn] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_warn { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_warn passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_warn is correct');
-wLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_warn is correct');
+[warn] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_error { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_error passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_error is correct');
-eLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_error is correct');
+[error] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_error { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_error passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_error is correct');
-eLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_error is correct');
+[error] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_fatal { "Look ma, data: $_" } qw{frew bar baz};
ok( eq_array(\@foo, [qw{frew bar baz}]), 'Dlog_fatal passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for Dlog_fatal is correct');
-fLook ma, data: "frew"
+is( $var, <<'OUT', 'Output for Dlog_fatal is correct');
+[fatal] Look ma, data: "frew"
"bar"
"baz"
OUT
my $bar = DlogS_fatal { "Look ma, data: $_" } [qw{frew bar baz}];
ok( eq_array($bar, [qw{frew bar baz}]), 'DlogS_fatal passes data through correctly');
-is( $var_log->var, <<'OUT', 'Output for DlogS_fatal is correct');
-fLook ma, data: [
+is( $var, <<'OUT', 'Output for DlogS_fatal is correct');
+[fatal] Look ma, data: [
"frew",
"bar",
"baz"
{
my @foo = Dlog_trace { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_trace passes nothing through correctly');
- is( $var_log->var, 'tnothing: ()', 'Output for Dlog_trace is correct');
+ is( $var, "[trace] nothing: ()\n", 'Output for Dlog_trace is correct');
}
{
my @foo = Dlog_debug { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_debug passes nothing through correctly');
- is( $var_log->var, 'dnothing: ()', 'Output for Dlog_debug is correct');
+ is( $var, "[debug] nothing: ()\n", 'Output for Dlog_debug is correct');
}
{
my @foo = Dlog_info { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_info passes nothing through correctly');
- is( $var_log->var, 'inothing: ()', 'Output for Dlog_info is correct');
+ is( $var, "[info] nothing: ()\n", 'Output for Dlog_info is correct');
}
{
my @foo = Dlog_warn { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_warn passes nothing through correctly');
- is( $var_log->var, 'wnothing: ()', 'Output for Dlog_warn is correct');
+ is( $var, "[warn] nothing: ()\n", 'Output for Dlog_warn is correct');
}
{
my @foo = Dlog_error { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_error passes nothing through correctly');
- is( $var_log->var, 'enothing: ()', 'Output for Dlog_error is correct');
+ is( $var, "[error] nothing: ()\n", 'Output for Dlog_error is correct');
}
{
my @foo = Dlog_fatal { "nothing: $_" } ();
ok( eq_array(\@foo, []), 'Dlog_fatal passes nothing through correctly');
- is( $var_log->var, 'fnothing: ()', 'Output for Dlog_fatal is correct');
+ is( $var, "[fatal] nothing: ()\n", 'Output for Dlog_fatal is correct');
}
+++ /dev/null
-package VarLogger;
-
-sub new { bless { var => undef }, __PACKAGE__ }
-sub var { $_[0]->{var} }
-
-sub debug { $_[0]->{var} = "d$_[1]" }
-sub is_debug { 1 }
-
-sub trace { $_[0]->{var} = "t$_[1]" }
-sub is_trace { 1 }
-
-sub error { $_[0]->{var} = "e$_[1]" }
-sub is_error { 1 }
-
-sub info { $_[0]->{var} = "i$_[1]" }
-sub is_info { 1 }
-
-sub fatal { $_[0]->{var} = "f$_[1]" }
-sub is_fatal { 1 }
-
-sub warn { $_[0]->{var} = "w$_[1]" }
-sub is_warn { 1 }
-
-1;
use strict;
use warnings;
-use lib 't/lib';
-use VarLogger;
use Log::Contextual qw{:log with_logger set_logger};
+use Log::Contextual::SimpleLogger;
use Test::More qw(no_plan);
-my $var_logger1 = VarLogger->new;
-my $var_logger2 = VarLogger->new;
-my $var_logger3 = VarLogger->new;
+my $var1;
+my $var2;
+my $var3;
+my $var_logger1 = Log::Contextual::SimpleLogger->new({
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var1 = shift },
+});
+
+my $var_logger2 = Log::Contextual::SimpleLogger->new({
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var2 = shift },
+});
+
+my $var_logger3 = Log::Contextual::SimpleLogger->new({
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var3 = shift },
+});
WITHLOGGER: {
with_logger sub { $var_logger2 } => sub {
};
- is( $var_logger1->var, 'dnothing!', 'inner scoped logger works' );
- is( $var_logger2->var, 'dfrew!', 'outer scoped logger works' );
+ is( $var1, "[debug] nothing!\n", 'inner scoped logger works' );
+ is( $var2, "[debug] frew!\n", 'outer scoped logger works' );
}
SETLOGGER: {
set_logger(sub { $var_logger3 });
log_debug { 'set_logger' };
- is( $var_logger3->var, 'dset_logger', 'set logger works' );
+ is( $var3, "[debug] set_logger\n", 'set logger works' );
}
SETWITHLOGGER: {
log_debug { 'this is a set inside a with' };
};
- is( $var_logger1->var, 'dnothing again!',
+ is( $var1, "[debug] nothing again!\n",
'inner scoped logger works after using set_logger'
);
- is( $var_logger3->var, 'dthis is a set inside a with',
+ is( $var3, "[debug] this is a set inside a with\n",
'set inside with works'
);
log_debug { 'frioux!' };
- is( $var_logger3->var, 'dfrioux!',
+ is( $var3, "[debug] frioux!\n",
q{set_logger's logger comes back after scoped logger}
);
}
VANILLA: {
log_trace { 'fiSMBoC' };
- is( $var_logger3->var, 'tfiSMBoC', 'trace works');
+ is( $var3, "[trace] fiSMBoC\n", 'trace works');
log_debug { 'fiSMBoC' };
- is( $var_logger3->var, 'dfiSMBoC', 'debug works');
+ is( $var3, "[debug] fiSMBoC\n", 'debug works');
log_info { 'fiSMBoC' };
- is( $var_logger3->var, 'ifiSMBoC', 'info works');
+ is( $var3, "[info] fiSMBoC\n", 'info works');
log_warn { 'fiSMBoC' };
- is( $var_logger3->var, 'wfiSMBoC', 'warn works');
+ is( $var3, "[warn] fiSMBoC\n", 'warn works');
log_error { 'fiSMBoC' };
- is( $var_logger3->var, 'efiSMBoC', 'error works');
+ is( $var3, "[error] fiSMBoC\n", 'error works');
log_fatal { 'fiSMBoC' };
- is( $var_logger3->var, 'ffiSMBoC', 'fatal works');
+ is( $var3, "[fatal] fiSMBoC\n", 'fatal works');
}
my @vars;
@vars = log_trace { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'tfiSMBoC: bar', 'log_trace works with input');
+ is( $var3, "[trace] fiSMBoC: bar\n", 'log_trace works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_trace passes data through correctly');
@vars = log_debug { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'dfiSMBoC: bar', 'log_debug works with input');
+ is( $var3, "[debug] fiSMBoC: bar\n", 'log_debug works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_debug passes data through correctly');
@vars = log_info { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'ifiSMBoC: bar', 'log_info works with input');
+ is( $var3, "[info] fiSMBoC: bar\n", 'log_info works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_info passes data through correctly');
@vars = log_warn { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'wfiSMBoC: bar', 'log_warn works with input');
+ is( $var3, "[warn] fiSMBoC: bar\n", 'log_warn works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_warn passes data through correctly');
@vars = log_error { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'efiSMBoC: bar', 'log_error works with input');
+ is( $var3, "[error] fiSMBoC: bar\n", 'log_error works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_error passes data through correctly');
@vars = log_fatal { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
- is( $var_logger3->var, 'ffiSMBoC: bar', 'log_fatal works with input');
+ is( $var3, "[fatal] fiSMBoC: bar\n", 'log_fatal works with input');
ok( eq_array(\@vars, [qw{foo bar baz}]), 'log_fatal passes data through correctly');
my $val;
$val = logS_trace { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'tfiSMBoC: foo', 'logS_trace works with input');
+ is( $var3, "[trace] fiSMBoC: foo\n", 'logS_trace works with input');
is( $val, 'foo', 'logS_trace passes data through correctly');
$val = logS_debug { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'dfiSMBoC: foo', 'logS_debug works with input');
+ is( $var3, "[debug] fiSMBoC: foo\n", 'logS_debug works with input');
is( $val, 'foo', 'logS_debug passes data through correctly');
$val = logS_info { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'ifiSMBoC: foo', 'logS_info works with input');
+ is( $var3, "[info] fiSMBoC: foo\n", 'logS_info works with input');
is( $val, 'foo', 'logS_info passes data through correctly');
$val = logS_warn { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'wfiSMBoC: foo', 'logS_warn works with input');
+ is( $var3, "[warn] fiSMBoC: foo\n", 'logS_warn works with input');
is( $val, 'foo', 'logS_warn passes data through correctly');
$val = logS_error { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'efiSMBoC: foo', 'logS_error works with input');
+ is( $var3, "[error] fiSMBoC: foo\n", 'logS_error works with input');
is( $val, 'foo', 'logS_error passes data through correctly');
$val = logS_fatal { 'fiSMBoC: ' . $_[0] } 'foo';
- is( $var_logger3->var, 'ffiSMBoC: foo', 'logS_fatal works with input');
+ is( $var3, "[fatal] fiSMBoC: foo\n", 'logS_fatal works with input');
is( $val, 'foo', 'logS_fatal passes data through correctly');
ok(!eval "logS_error { 'frew' } 'bar', 'baz'; 1", 'logS_$level dies from too many args');