line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2007-2017 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
1
|
|
|
1
|
|
12252
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Log::Report::Dispatcher::Syslog; |
9
|
1
|
|
|
1
|
|
6
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.23'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use base 'Log::Report::Dispatcher'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
126
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Log::Report 'log-report'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
10
|
use Sys::Syslog qw/:standard :extended :macros/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
277
|
|
17
|
1
|
|
|
1
|
|
7
|
use Log::Report::Util qw/@reasons expand_reasons/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
18
|
1
|
|
|
1
|
|
7
|
use Encode qw/encode/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use File::Basename qw/basename/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
738
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %default_reasonToPrio = |
23
|
|
|
|
|
|
|
( TRACE => LOG_DEBUG |
24
|
|
|
|
|
|
|
, ASSERT => LOG_DEBUG |
25
|
|
|
|
|
|
|
, INFO => LOG_INFO |
26
|
|
|
|
|
|
|
, NOTICE => LOG_NOTICE |
27
|
|
|
|
|
|
|
, WARNING => LOG_WARNING |
28
|
|
|
|
|
|
|
, MISTAKE => LOG_WARNING |
29
|
|
|
|
|
|
|
, ERROR => LOG_ERR |
30
|
|
|
|
|
|
|
, FAULT => LOG_ERR |
31
|
|
|
|
|
|
|
, ALERT => LOG_ALERT |
32
|
|
|
|
|
|
|
, FAILURE => LOG_EMERG |
33
|
|
|
|
|
|
|
, PANIC => LOG_CRIT |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
@reasons==keys %default_reasonToPrio |
37
|
|
|
|
|
|
|
or panic __"not all reasons have a default translation"; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $active; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub init($) |
43
|
1
|
|
|
1
|
0
|
3
|
{ my ($self, $args) = @_; |
44
|
1
|
|
50
|
|
|
8
|
$args->{format_reason} ||= 'IGNORE'; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
10
|
$self->SUPER::init($args); |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
|
|
|
4
|
error __x"max one active syslog dispatcher, attempt for {new} have {old}" |
49
|
|
|
|
|
|
|
, new => $self->name, old => $active |
50
|
|
|
|
|
|
|
if $active; |
51
|
1
|
|
|
|
|
5
|
$active = $self->name; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
setlogsock(delete $args->{logsocket}) |
54
|
1
|
50
|
|
|
|
4
|
if $args->{logsocket}; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
33
|
|
|
56
|
my $ident = delete $args->{identity} || basename $0; |
57
|
1
|
|
50
|
|
|
7
|
my $flags = delete $args->{flags} || 'pid,nowait'; |
58
|
1
|
|
50
|
|
|
7
|
my $fac = delete $args->{facility} || 'user'; |
59
|
1
|
|
|
|
|
24
|
openlog $ident, $flags, $fac; # doesn't produce error. |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
48
|
$self->{LRDS_incl_dom} = delete $args->{include_domain}; |
62
|
1
|
|
50
|
|
|
8
|
$self->{LRDS_charset} = delete $args->{charset} || "utf-8"; |
63
|
1
|
|
50
|
1
|
|
9
|
$self->{LRDS_format} = $args->{format} || sub {$_[0]}; |
|
1
|
|
|
|
|
5
|
|
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
11
|
$self->{prio} = +{ %default_reasonToPrio }; |
66
|
1
|
50
|
|
|
|
6
|
if(my $to_prio = delete $args->{to_prio}) |
67
|
1
|
|
|
|
|
4
|
{ my @to = @$to_prio; |
68
|
1
|
|
|
|
|
4
|
while(@to) |
69
|
1
|
|
|
|
|
3
|
{ my ($reasons, $level) = splice @to, 0, 2; |
70
|
1
|
|
|
|
|
5
|
my @reasons = expand_reasons $reasons; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
42
|
my $prio = Sys::Syslog::xlate($level); |
73
|
1
|
50
|
|
|
|
58
|
error __x"syslog level '{level}' not understood", level => $level |
74
|
|
|
|
|
|
|
if $prio eq -1; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
8
|
$self->{prio}{$_} = $prio for @reasons; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
5
|
$self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub close() |
84
|
1
|
|
|
1
|
1
|
3
|
{ my $self = shift; |
85
|
1
|
|
|
|
|
3
|
undef $active; |
86
|
1
|
|
|
|
|
5
|
closelog; |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
28
|
$self->SUPER::close; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#-------------- |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub format(;$) |
94
|
1
|
|
|
1
|
1
|
2
|
{ my $self = shift; |
95
|
1
|
50
|
|
|
|
4
|
@_ ? $self->{LRDS_format} = shift : $self->{LRDS_format}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#-------------- |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub log($$$$$) |
101
|
1
|
|
|
1
|
1
|
5
|
{ my ($self, $opts, $reason, $msg, $domain) = @_; |
102
|
1
|
50
|
|
|
|
15
|
my $text = $self->translate($opts, $reason, $msg) or return; |
103
|
1
|
|
|
|
|
5
|
my $format = $self->format; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# handle each line in message separately |
106
|
1
|
|
|
|
|
6
|
$text =~ s/\s+$//s; |
107
|
1
|
|
|
|
|
4
|
my @text = split /\n/, $format->($text, $domain, $msg, %$opts); |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
4
|
my $prio = $self->reasonToPrio($reason); |
110
|
1
|
|
|
|
|
3
|
my $charset = $self->{LRDS_charset}; |
111
|
|
|
|
|
|
|
|
112
|
1
|
50
|
33
|
|
|
4
|
if($self->{LRDS_incl_dom} && $domain) |
113
|
0
|
|
|
|
|
0
|
{ $domain =~ s/\%//g; # security |
114
|
0
|
|
|
|
|
0
|
syslog $prio, "$domain %s", encode($charset, shift @text); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
syslog $prio, "%s", encode($charset, $_) |
118
|
1
|
|
|
|
|
8
|
for @text; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
1
|
1
|
3
|
sub reasonToPrio($) { $_[0]->{prio}{$_[1]} } |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |