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