/usr/share/perl5/BackupManager/Logger.pm is in backup-manager 0.7.10.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | #!/usr/bin/perl
package BackupManager::Logger;
=head1 NAME
BackupManager::Logger - BackupManager's Logger engine.
=head1 DESCRIPTION
It's a nice to use wrapper on the top of syslog.
Will provide one function per syslog level.
=head2 FUNCTIONS
debug, info, notice, warning, error, critic and alert behave
the same : take a string and log it with the appropriate level.
=cut
use Exporter ;
@ISA = ( 'Exporter' ) ;
@EXPORT = qw (
&debug
&info
¬ice
&warning
&error
&critic
&alert
);
use strict;
use warnings;
use Sys::Syslog qw(:DEFAULT setlogsock);
sub basename($);
use constant DEFAULT_FACILITY => 'cron';
our $LOG_IS_ENABLED;
our $basename;
my $LOG_FLAGS = {
debug => 1,
info => 1,
notice => 1,
warning => 1,
err => 1,
crit => 1,
alert => 1
};
my $g_prefix = "";
my %g_rh_label = (
info => 'info ',
notice => 'note ',
err => 'error',
warning => 'warn ',
debug => 'debug',
crit => 'crit ',
alert => 'alert'
);
my $facility;
BEGIN {
$basename = $0;
$basename =~ s%^.*/%%;
$facility=DEFAULT_FACILITY unless $facility=$ENV{BM_LOGGER_FACILITY};
setlogsock('unix');
openlog($basename, 'pid', $facility);
}
END {
closelog();
}
sub debug($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('debug', $message);
}
sub info($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('info', $message);
}
sub notice($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('notice', $message);
}
sub warning($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('warning', $message);
}
sub error ($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('err', $message);
}
sub critic ($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('crit', $message);
}
sub alert ($)
{
my ($message) = @_;
return 0 unless defined $message and length $message;
return log_with_syslog('alert', $message);
}
sub basename($)
{
my $full_path = shift;
return undef unless defined $full_path;
chomp($full_path);
$full_path =~ s/\/*$//;
my @words = split(/\//, $full_path);
return $words[$#words];
}
sub log_with_syslog ($$)
{
my ($level, $message) = @_;
return 0 unless defined $level and defined $message;
my $caller = 2;
my ($package, $filename, $line, $fonction) = caller ($caller);
$package = "" unless defined $package;
$filename = "" unless defined $filename;
$line = 0 unless defined $line;
$fonction = $basename unless defined $fonction;
$level = lc($level);
$level = 'info' unless defined $level and length $level;
return 0 unless $LOG_FLAGS->{$level};
unless (defined $message and length $message) {
$message = "[void]";
}
my $level_str = $g_rh_label{$level};
$message = $level_str . " * $message";
$message .= " - $fonction ($filename l. $line)" if $line;
$message =~ s/%/%%/g;
$message = $g_prefix . " > " . $message if (length $g_prefix);
return syslog($level, $message);
}
=head1 AUTHOR
Alexis Sukrieh <sukria@sukria.net>
=cut
1;
|