]> git.proxmox.com Git - pve-common.git/blob - data/PVE/SafeSyslog.pm
allow to pass single '-' as argument.
[pve-common.git] / data / PVE / SafeSyslog.pm
1 package PVE::SafeSyslog;
2
3 use strict;
4 use warnings;
5 use File::Basename;
6 use Sys::Syslog ();
7 use Encode;
8
9 use vars qw($VERSION @ISA @EXPORT);
10
11 $VERSION = '1.00';
12
13 require Exporter;
14
15 @ISA = qw(Exporter);
16
17 @EXPORT = qw(syslog initlog);
18
19 my $log_tag = "unknown";
20
21 # never log to console - thats too slow, and
22 # it corrupts the DBD database connection!
23
24 sub syslog {
25 eval { Sys::Syslog::syslog (@_); }; # 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;