move handle_log_request logic into router
[p5sagit/Log-Contextual.git] / t / log-with-levels.t
CommitLineData
5fd26f45 1use strict;
2use warnings;
3
4use Log::Contextual qw{:dlog :log with_logger set_logger}, -levels => ['custom'];
5use Log::Contextual::SimpleLogger;
6use Test::More qw(no_plan);
7
8my $logger = DumbLogger->new;
9
10set_logger(sub { $logger });
11
12log_custom { 'fiSMBoC' };
13is( $DumbLogger::var, "fiSMBoC", "custom works");
14
15my @vars = log_custom { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
16is( $DumbLogger::var, "fiSMBoC: bar", "log_custom works with input");
17ok( eq_array(\@vars, [qw{foo bar baz}]), "log_custom passes data through correctly");
18
19my $val = logS_custom { 'fiSMBoC: ' . $_[0] } 'foo';
20is( $DumbLogger::var, "fiSMBoC: foo", "logS_custom works with input");
21is( $val, 'foo', "logS_custom passes data through correctly");
22
23my @foo = Dlog_custom { "Look ma, data: $_" } qw{frew bar baz};
24
25ok(
26 eq_array(\@foo, [qw{frew bar baz}]),
27 "Dlog_custom passes data through correctly"
28);
29is(
30 $DumbLogger::var, qq(Look ma, data: "frew"\n"bar"\n"baz"\n),
31 "Output for Dlog_custom is correct"
32);
33
34my $bar = DlogS_custom { "Look ma, data: $_" } [qw{frew bar baz}];
35ok(
36 eq_array($bar, [qw{frew bar baz}]),
37 'DlogS_custom passes data through correctly'
38);
39is(
40 $DumbLogger::var, qq(Look ma, data: [\n "frew",\n "bar",\n "baz"\n]\n),
41 "Output for DlogS_custom is correct"
42);
43
44@foo = Dlog_custom { "nothing: $_" } ();
45ok( eq_array(\@foo, []), "Dlog_custom passes nothing through correctly");
46is( $DumbLogger::var, "nothing: ()", "Output for Dlog_custom is correct");
47
8112b699 48ok(!main->can($_), "$_ not imported")
5fd26f45 49 for map +( "log_$_", "logS_$_" ), qw(debug trace warn info error fatal);
50
51ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies');
52
53BEGIN {
54 package DumbLogger;
55
56 our $var;
57 sub new { bless {}, 'DumbLogger' }
58 sub is_custom { 1 }
59 sub custom { $var = $_[1] }
60
61 1;
62}