| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Logger::Syslog; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Dancer2 logger engine for Sys::Syslog |
|
3
|
|
|
|
|
|
|
$Dancer2::Logger::Syslog::VERSION = '0.3'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
334660
|
use Moo; |
|
|
3
|
|
|
|
|
19786
|
|
|
|
3
|
|
|
|
|
16
|
|
|
6
|
3
|
|
|
3
|
|
2482
|
use File::Basename 'basename'; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
171
|
|
|
7
|
3
|
|
|
3
|
|
28821
|
use Sys::Syslog; |
|
|
3
|
|
|
|
|
30213
|
|
|
|
3
|
|
|
|
|
205
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1102
|
use Dancer2::Core::Types; |
|
|
3
|
|
|
|
|
14865
|
|
|
|
3
|
|
|
|
|
1686
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Logger'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'log_open' => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
isa => Bool, |
|
16
|
|
|
|
|
|
|
lazy => 1, |
|
17
|
|
|
|
|
|
|
builder => '_syslog_open', |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Set by calling function |
|
21
|
|
|
|
|
|
|
has facility => ( |
|
22
|
|
|
|
|
|
|
is => 'ro', |
|
23
|
|
|
|
|
|
|
isa => Str, |
|
24
|
|
|
|
|
|
|
lazy => 1, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has ident => ( |
|
28
|
|
|
|
|
|
|
is => 'ro', |
|
29
|
|
|
|
|
|
|
isa => Str, |
|
30
|
|
|
|
|
|
|
lazy => 1, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has logopt => ( |
|
34
|
|
|
|
|
|
|
is => 'ro', |
|
35
|
|
|
|
|
|
|
isa => Str, |
|
36
|
|
|
|
|
|
|
lazy => 1, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _syslog_open { |
|
40
|
2
|
|
|
2
|
|
805
|
my $self = shift; |
|
41
|
|
|
|
|
|
|
|
|
42
|
2
|
|
50
|
|
|
17
|
my $facility = $self->facility || 'USER'; |
|
43
|
2
|
|
33
|
|
|
22
|
my $ident = $self->ident |
|
44
|
|
|
|
|
|
|
|| $self->app_name |
|
45
|
|
|
|
|
|
|
|| $ENV{DANCER_APPDIR} |
|
46
|
|
|
|
|
|
|
|| basename($0); |
|
47
|
2
|
|
50
|
|
|
12
|
my $logopt = $self->logopt || 'pid'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
11
|
openlog($ident, $logopt, $facility); |
|
50
|
2
|
|
|
|
|
665
|
1; # openlog() will have croaked if it can't connect |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
443
|
sub DESTROY { closelog() } |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub log { |
|
56
|
7
|
|
|
7
|
1
|
92312
|
my ($self, $level, $message) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
7
|
|
|
|
|
83
|
$self->log_open; |
|
59
|
|
|
|
|
|
|
|
|
60
|
7
|
|
|
|
|
109
|
my $syslog_levels = { |
|
61
|
|
|
|
|
|
|
core => 'debug', |
|
62
|
|
|
|
|
|
|
debug => 'debug', |
|
63
|
|
|
|
|
|
|
warning => 'warning', |
|
64
|
|
|
|
|
|
|
error => 'err', |
|
65
|
|
|
|
|
|
|
info => 'info', |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
7
|
|
50
|
|
|
16
|
$level = $syslog_levels->{$level} || 'debug'; |
|
69
|
7
|
|
|
|
|
18
|
my $fm = $self->format_message($level => $message); |
|
70
|
7
|
|
|
|
|
2418
|
syslog($level, $fm); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |