File: 07_hardwired.t

package info (click to toggle)
liblog-dispatch-config-perl 1.04-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 224 kB
  • sloc: perl: 233; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use Test::More tests => 7;

END { unlink 't/log.out' if -e 't/log.out' }

{
    package Log::Dispatch::Configurator::Hardwired;
    use base qw(Log::Dispatch::Configurator);

    sub new { bless {}, shift }

    sub get_attrs_global {
	my $self = shift;
	return {
	    format => undef,
	    dispatchers => [ qw(file screen) ],
	};
    }

    sub get_attrs {
	my($self, $name) = @_;
	if ($name eq 'file') {
	    return {
		class     => 'Log::Dispatch::File',
		min_level => 'debug',
		filename  => 't/log.out',
		mode      => 'append',
		format    => '[%d] [%p] %m at %F line %L%n',
	    };
	} elsif ($name eq 'screen') {
	    return {
		class     => 'Log::Dispatch::Screen',
		min_level => 'info',
		stderr    => 1,
		format    => '%m',
	    };
	}
    }

    # every time it needs reload
    sub needs_reload { 1 }
}

use Log::Dispatch::Config;

my $config = Log::Dispatch::Configurator::Hardwired->new;
isa_ok $config, 'Log::Dispatch::Configurator';
isa_ok $config, 'Log::Dispatch::Configurator::Hardwired';

Log::Dispatch::Config->configure_and_watch($config);

my $disp = Log::Dispatch::Config->instance;
isa_ok $disp->{outputs}->{file}, 'Log::Dispatch::File';

my $disp2 = Log::Dispatch::Config->instance;
isa_ok $disp->{outputs}->{file}, 'Log::Dispatch::File';

isnt "$disp", "$disp2", "$disp - $disp2";

my $disp3 = Log::Dispatch::Config->instance;
isnt "$disp", "$disp3", "$disp - $disp3";
isnt "$disp2", "$disp3", "$disp2 - $disp3";