File Coverage

blib/lib/Log/Any/Adapter/LinuxJournal.pm
Criterion Covered Total %
statement 6 8 75.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 9 11 81.8


line stmt bran cond sub pod time code
1             package Log::Any::Adapter::LinuxJournal 0.172762;
2              
3             # ABSTRACT: Log::Any adapter for the systemd journal on Linux
4              
5 1     1   761 use v5.12;
  1         5  
6 1     1   8 use warnings;
  1         2  
  1         52  
7              
8 1     1   118 use Linux::Systemd::Journal::Write 1.172760;
  0            
  0            
9             use Log::Any::Adapter::Util '1.700';
10             use base 'Log::Any::Adapter::Base';
11              
12             sub init {
13             my $self = shift;
14             $self->{jnl} = Linux::Systemd::Journal::Write->new(@_, caller_level => 2);
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__