]>
Commit | Line | Data |
---|---|---|
1 | package PVE::SafeSyslog; | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use File::Basename; | |
6 | use Sys::Syslog (); | |
7 | use Encode; | |
8 | use base 'Exporter'; | |
9 | ||
10 | our $VERSION = '1.00'; | |
11 | ||
12 | ||
13 | our @EXPORT = qw(syslog initlog); | |
14 | ||
15 | my $log_tag = "unknown"; | |
16 | ||
17 | # never log to console - thats too slow, and | |
18 | # it corrupts the DBD database connection! | |
19 | ||
20 | sub syslog { | |
21 | my ($level, @param) = @_; | |
22 | ||
23 | $level = 'warning' if $level eq 'warn'; | |
24 | ||
25 | eval { Sys::Syslog::syslog ($level, @param); }; # ignore errors | |
26 | } | |
27 | ||
28 | sub initlog { | |
29 | my ($tag, $facility) = @_; | |
30 | ||
31 | if ($tag) { | |
32 | $tag = basename($tag); | |
33 | ||
34 | $tag = encode("ascii", decode_utf8($tag)); | |
35 | ||
36 | $log_tag = $tag; | |
37 | } | |
38 | ||
39 | $facility = "daemon" if !$facility; | |
40 | ||
41 | # never log to console - thats too slow | |
42 | Sys::Syslog::setlogsock ('unix'); | |
43 | ||
44 | Sys::Syslog::openlog ($log_tag, 'pid', $facility); | |
45 | } | |
46 | ||
47 | sub tag { | |
48 | return $log_tag; | |
49 | } | |
50 | ||
51 | 1; |