/
00-functionality.t
56 lines (43 loc) · 1.43 KB
/
00-functionality.t
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
use Test;
use lib 'lib';
use lib './t/resources/00-config-file';
use LogP6 :configure;
use LogP6::WriterConf::Journald;
use Custom;
plan 4;
writer(LogP6::WriterConf::Journald.new(
:name<journald-1>, :systemd(Custom::TestSystemd.new), :pattern('%level %msg'),
:use-priority, :use-code-line, :use-code-file, :use-code-func, :use-mdc,
:auto-exceptions
));
writer(LogP6::WriterConf::Journald.new(
:name<journald-2>, :systemd(Custom::TestSystemd.new), :pattern('%msg'),
:use-priority
));
cliche(:name<journald-1>, :matcher<journald-1>, grooves => ('journald-1', level($trace)));
cliche(:name<journald-2>, :matcher<journald-2>, grooves => ('journald-2', level($trace)));
test('code');
init-from-file('./t/resources/00-config-file/log-p6.json');
test('file');
sub foo($log) {
$log.warn('boom'); return callframe(0);
}
sub test($type) {
my $log;
my $frame;
$log = get-logger('journald-1');
$log.mdc-put('OBJ', 'value');
$log.mdc-put('VAL', 'obj');
$frame = foo($log);
is-deeply get-writer('journald-1').systemd.sent.sort,
('CODE_FILE=' ~ $frame.file, 'CODE_FUNC=' ~ $frame.code.name,
'CODE_LINE=' ~ $frame.line, 'MESSAGE=WARN boom', 'OBJ=value',
'PRIORITY=4', 'VAL=obj'), "$type journald-1 sent";
$log = get-logger('journald-2');
$log.mdc-put('OBJ', 'value');
$log.mdc-put('VAL', 'obj');
$frame = foo($log);
is-deeply get-writer('journald-2').systemd.sent.sort,
('MESSAGE=boom', 'PRIORITY=4',), "$type journald-2 sent";
}
done-testing;