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.5'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
418726
|
use Moo; |
|
3
|
|
|
|
|
15843
|
|
|
3
|
|
|
|
|
11
|
|
6
|
3
|
|
|
3
|
|
2035
|
use File::Basename 'basename'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
156
|
|
7
|
3
|
|
|
3
|
|
716
|
use Sys::Syslog qw(:standard :extended); |
|
3
|
|
|
|
|
13432
|
|
|
3
|
|
|
|
|
387
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
971
|
use Dancer2::Core::Types; |
|
3
|
|
|
|
|
11831
|
|
|
3
|
|
|
|
|
1469
|
|
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
|
|
|
|
|
|
|
has host => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => Str, |
42
|
|
|
|
|
|
|
lazy => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has type => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => Str, |
48
|
|
|
|
|
|
|
lazy => 1, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has port => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
isa => Str, |
54
|
|
|
|
|
|
|
lazy => 1, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _syslog_open { |
59
|
2
|
|
|
2
|
|
764
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
50
|
|
|
17
|
my $facility = $self->facility || 'USER'; |
62
|
|
|
|
|
|
|
my $ident = $self->ident |
63
|
|
|
|
|
|
|
|| $self->app_name |
64
|
|
|
|
|
|
|
|| $ENV{DANCER_APPDIR} |
65
|
2
|
|
0
|
|
|
22
|
|| basename($0); |
66
|
2
|
|
50
|
|
|
11
|
my $logopt = $self->logopt || 'pid'; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
8
|
if ( $self->host && ( $Sys::Syslog::VERSION >= 0.33 )) { |
69
|
0
|
|
|
|
|
0
|
my $host = $self->host; |
70
|
0
|
|
0
|
|
|
0
|
my $type = $self->type || 'udp'; |
71
|
0
|
|
0
|
|
|
0
|
my $port = $self->port || 53; |
72
|
0
|
|
|
|
|
0
|
setlogsock( { host => $host, type => $type, port => $port } ) |
73
|
|
|
|
|
|
|
} |
74
|
2
|
|
|
|
|
11
|
openlog($ident, $logopt, $facility); |
75
|
2
|
|
|
|
|
414
|
1; # openlog() will have croaked if it can't connect |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
1
|
|
891
|
sub DESTROY { closelog() } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub log { |
81
|
|
|
|
|
|
|
my ($self, $level, $message) = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self->log_open; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $syslog_levels = { |
86
|
|
|
|
|
|
|
core => 'debug', |
87
|
|
|
|
|
|
|
debug => 'debug', |
88
|
|
|
|
|
|
|
warning => 'warning', |
89
|
|
|
|
|
|
|
error => 'err', |
90
|
|
|
|
|
|
|
info => 'info', |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$level = $syslog_levels->{$level} || 'debug'; |
94
|
|
|
|
|
|
|
my $fm = $self->format_message($level => $message); |
95
|
|
|
|
|
|
|
syslog($level, $fm); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |