/usr/share/cricket/lib/Common/Log.pm is in cricket 1.0.5-21.
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 | # -*- perl -*-
# Cricket: a configuration, polling and data display wrapper for RRD files
#
# Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
package Common::Log;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(Debug Warn Info Die Error LogMonitor isDebug);
$kLogDebug = 9;
$kLogMonitor = 8;
$kLogInfo = 7;
$kLogWarn = 5;
$kLogError = 1;
$gCurLogLevel = $kLogWarn;
%kLogNameMap = (
'debug' => $kLogDebug,
'monitor' => $kLogMonitor,
'info' => $kLogInfo,
'warn' => $kLogWarn,
'error' => $kLogError
);
%kLogNameReverseMap = (
$kLogDebug => 'debug',
$kLogMonitor => 'monitor',
$kLogInfo => 'info',
$kLogWarn => 'warn',
$kLogError => 'error'
);
$kLogMinimal = 1;
$kLogStandard = 2;
$kLogExtended = 3;
$gCurLogFormat = $kLogStandard;
%kLogFormatMap = (
'minimal' => $kLogMinimal,
'standard' => $kLogStandard,
'extended' => $kLogExtended
);
sub Log {
my($level, @msg) = @_;
my($msg) = join('', @msg);
return unless ($level <= $gCurLogLevel);
my($severity) = ' ';
$severity = '*' if (($level == $kLogWarn) || ($level == $kLogError));
if ($gCurLogFormat == 2) {
my($stuff) = timeStr(time()) . $severity;
if(defined($main::th)) {
print STDERR "[$stuff] ($main::th) $msg\n";
} else {
print STDERR "[$stuff] $msg\n";
}
} elsif ($gCurLogFormat == 3) {
my($stuff) = timeStr(time()) . $severity;
my($levelname) = ucfirst($kLogNameReverseMap{$level});
printf STDERR ("[$stuff] %-5s $msg\n", $levelname);
} else {
my($levelname) = ucfirst($kLogNameReverseMap{$level});
printf STDERR ("[%-5s%1s] $msg\n", $levelname, $severity);
}
}
sub Die {
Log($kLogError, @_);
die("Exiting due to unrecoverable error.\n");
}
sub Error {
Log($kLogError, @_);
}
sub Warn {
Log($kLogWarn, @_);
}
sub Debug {
Log($kLogDebug, @_);
}
sub Info {
Log($kLogInfo, @_);
}
sub LogMonitor {
Log($kLogMonitor, @_);
}
sub isDebug {
return 1 if $gCurLogLevel >= $kLogDebug;
return 0;
}
sub timeStr {
my($t) = ($_[0] =~ /(\d*)/);
my(@months) = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec");
my($sec,$min,$hour,$mday,$mon,$year) = localtime($t);
return sprintf("%02d-%s-%04d %02d:%02d:%02d", $mday, $months[$mon],
$year + 1900, $hour, $min, $sec);
}
sub setLevel {
my($level) = @_;
my($ilevel) = $gCurLogLevel;
if (defined($kLogNameMap{lc($level)})) {
$gCurLogLevel = $kLogNameMap{lc($level)};
Common::Log::Info("Log level changed from ",
$kLogNameReverseMap{$ilevel}, " to $level.");
} else {
Common::Log::Warn("Log level name $level unknown. " .
"Defaulting to 'info'.");
$gCurLogLevel = $kLogNameMap{lc('info')};
}
}
sub setFormat {
my($format) = @_;
if (defined($kLogFormatMap{lc($format)})) {
$gCurLogFormat = $kLogFormatMap{lc($format)};
} else {
Common::Log::Warn("Log format name $format unknown. " .
"Defaulting to 'standard'.");
$gCurLogFormat = $kLogFormatMap{lc('standard')};
}
}
1;
# Local Variables:
# mode: perl
# indent-tabs-mode: nil
# tab-width: 4
# perl-indent-level: 4
# End:
|