]> git.proxmox.com Git - pve-common.git/blame - src/PVE/SafeSyslog.pm
runtest.pl: use lib '.' - because newer perl does not have that by default
[pve-common.git] / src / PVE / SafeSyslog.pm
CommitLineData
e143e9d8
DM
1package PVE::SafeSyslog;
2
3use strict;
4use warnings;
5use File::Basename;
6use Sys::Syslog ();
7use Encode;
8
9use vars qw($VERSION @ISA @EXPORT);
10
11$VERSION = '1.00';
12
13require Exporter;
14
15@ISA = qw(Exporter);
16
17@EXPORT = qw(syslog initlog);
18
19my $log_tag = "unknown";
20
21# never log to console - thats too slow, and
22# it corrupts the DBD database connection!
23
24sub syslog {
25 eval { Sys::Syslog::syslog (@_); }; # ignore errors
26}
27
28sub 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
47sub tag {
48 return $log_tag;
49}
50
511;