]> git.proxmox.com Git - pve-common.git/blame - src/PVE/SafeSyslog.pm
json schema: add format description for pve-storage-id standard option
[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;
0681aa71 8use base 'Exporter';
e143e9d8 9
0681aa71 10our $VERSION = '1.00';
e143e9d8 11
e143e9d8 12
0681aa71 13our @EXPORT = qw(syslog initlog);
e143e9d8
DM
14
15my $log_tag = "unknown";
9bbc4e17 16
e143e9d8
DM
17# never log to console - thats too slow, and
18# it corrupts the DBD database connection!
19
20sub syslog {
d4218592
FE
21 my ($level, @param) = @_;
22
23 $level = 'warning' if $level eq 'warn';
24
25 eval { Sys::Syslog::syslog ($level, @param); }; # ignore errors
e143e9d8
DM
26}
27
28sub initlog {
29 my ($tag, $facility) = @_;
30
9bbc4e17 31 if ($tag) {
e143e9d8
DM
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;