1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
# --
# Kernel/System/Log/SysLog.pm - a wrapper for Sys::Syslog or xyz::Syslog
# Copyright (C) 2001-2005 Martin Edenhofer <martin+code@otrs.org>
# --
# $Id: SysLog.pm,v 1.10 2005/02/10 13:37:10 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
package Kernel::System::Log::SysLog;
use strict;
use Sys::Syslog qw(:DEFAULT setlogsock);
use Kernel::System::Encode;
use vars qw($VERSION);
$VERSION = '$Revision: 1.10 $ ';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
# --
sub new {
my $Type = shift;
my %Param = @_;
# allocate new hash for object
my $Self = {};
bless ($Self, $Type);
# get config object
if (!$Param{ConfigObject}) {
die "Got no ConfigObject!";
}
else {
$Self->{ConfigObject} = $Param{ConfigObject};
}
# create encode object
$Self->{EncodeObject} = Kernel::System::Encode->new(
%Param,
);
# set syslog facility
$Self->{SysLogFacility} = $Param{ConfigObject}->Get('LogModule::SysLog::Facility') || 'user';
return $Self;
}
# --
sub Log {
my $Self = shift;
my %Param = @_;
# convert Message because syslog can't work with utf-8
if ($Self->{ConfigObject}->Get('DefaultCharset') =~ /^utf(-8|8)$/i) {
$Param{Message} = $Self->{EncodeObject}->Convert(
Text => $Param{Message},
From => 'utf8',
To => $Self->{ConfigObject}->Get('LogModule::SysLog::Charset') || 'iso-8859-15',
Force => 1,
);
}
# start syslog connect
setlogsock('unix');
openlog($Param{LogPrefix}, 'cons,pid', $Self->{SysLogFacility});
if ($Param{Priority} =~ /debug/i) {
syslog('debug', "[Debug][$Param{Module}][$Param{Line}] $Param{Message}");
}
elsif ($Param{Priority} =~ /info/i) {
syslog('info', "[Info][$Param{Module}] $Param{Message}");
}
elsif ($Param{Priority} =~ /notice/i) {
syslog('notice', "[Notice][$Param{Module}] $Param{Message}");
}
elsif ($Param{Priority} =~ /error/i) {
syslog('err', "[Error][$Param{Module}][Line:$Param{Line}]: $Param{Message}");
}
else {
# print error messages to STDERR
print STDERR "[Error][$Param{Module}] Priority: '$Param{Priority}' not defined! Message: $Param{Message}\n";
# and of course to syslog
syslog('err', "[Error][$Param{Module}] Priority: '$Param{Priority}' not defined! Message: $Param{Message}");
}
# --
# close syslog request
# --
closelog();
return;
}
# --
1;
|