File Coverage

blib/lib/Log/Any/Adapter/Journal.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Log::Any::Adapter::Journal;
2              
3             # ABSTRACT: Adapter for Log::Any that outputs with a priority prefix that systemd's journal can parse
4              
5 1     1   670 use 5.010;
  1         4  
6 1     1   6 use strict;
  1         2  
  1         19  
7 1     1   4 use warnings;
  1         2  
  1         28  
8              
9 1     1   5 use Log::Any::Adapter::Util qw(logging_methods numeric_level);
  1         2  
  1         68  
10 1     1   495 use parent 'Log::Any::Adapter::Screen';
  1         307  
  1         5  
11 1     1   2709 use Class::Method::Modifiers;
  1         1556  
  1         159  
12              
13             our $VERSION = '1.0';
14              
15             # sub init {
16             # my ($self) = @_;
17             # }
18              
19             # For each of the logging methods exposed by Log::Any, add the level
20             # prefix in angled brackets.
21             for my $method ( logging_methods ) {
22             my $level = numeric_level( $method );
23              
24             # Journal doesn't recognize trace (8), print as debug instead
25             $level = 7 if $level > 7;
26              
27             before $method => sub {
28             $_[1] = "<$level>$_[1]" unless $_[0]->{use_color};
29             };
30             }
31              
32             # Log::Any levels Journal levels
33             # 0 emergency 0 emerg
34             # 1 alert 1 alert
35             # 2 critical 2 crit
36             # 3 error 3 err
37             # 4 warning 4 warning
38             # 5 notice 5 notice
39             # 6 info 6 info
40             # 7 debug 7 debug
41             # 8 trace
42              
43             1;
44              
45             __END__