line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::LinuxJournal 0.172580; # TRIAL |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Log::Any adapter for the systemd journal on Linux |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
444
|
use v5.12; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
67
|
use Linux::Systemd::Journal::Write; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Log::Any::Adapter::Util '1.051'; |
10
|
|
|
|
|
|
|
use base 'Log::Any::Adapter::Base'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub init { |
13
|
|
|
|
|
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
$self->{jnl} = Linux::Systemd::Journal::Write->new(@_); |
15
|
|
|
|
|
|
|
return; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub structured { |
19
|
|
|
|
|
|
|
my ($self, $level, $category, @args) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %details = ( |
22
|
|
|
|
|
|
|
PRIORITY => $level, |
23
|
|
|
|
|
|
|
CATEGORY => $category, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my @msg; |
27
|
|
|
|
|
|
|
while (my $arg = shift @args) { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# TODO journal can only usefully take k => v, flatten v |
30
|
|
|
|
|
|
|
if (!ref $arg) { |
31
|
|
|
|
|
|
|
push @msg, $arg; |
32
|
|
|
|
|
|
|
} elsif (ref $arg eq 'HASH') { |
33
|
|
|
|
|
|
|
@details{keys %{$arg}} = values %{$arg}; |
34
|
|
|
|
|
|
|
} elsif (ref $arg eq 'ARRAY') { |
35
|
|
|
|
|
|
|
while (my ($k, $v) = (shift @{$arg}, shift @{$arg})) { |
36
|
|
|
|
|
|
|
$details{$k} = $v; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} else { |
39
|
|
|
|
|
|
|
push @msg, Log::Any::Adapter::Util::dump_one_line($arg); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{jnl}->send(join(' ', @msg), \%details); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# TODO optionally disable debug |
49
|
|
|
|
|
|
|
for my $method (Log::Any::Adapter::Util::detection_methods()) { |
50
|
|
|
|
|
|
|
no strict 'refs'; ## no critic |
51
|
|
|
|
|
|
|
*$method = sub {1}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |