Archived
1
0
Fork 0

Log: ERROR2 is now ALERT

This commit is contained in:
Mercier Pierre-Olivier 2013-09-28 11:09:47 +02:00
commit 1a142a9759

View file

@ -11,7 +11,7 @@ use Term::ANSIColor qw(:constants);
use constant { use constant {
FATAL => 1, FATAL => 1,
ERROR2 => 2, ALERT => 2,
ERROR => 3, ERROR => 3,
WARN => 4, WARN => 4,
DONE => 5, DONE => 5,
@ -21,7 +21,7 @@ use constant {
TRACE => 9, TRACE => 9,
}; };
our @EXPORT = qw(log FATAL ERROR2 ERROR WARN DONE USAGE INFO DEBUG TRACE); our @EXPORT = qw(log FATAL ALERT ERROR WARN DONE USAGE INFO DEBUG TRACE);
our $display_level = 7; our $display_level = 7;
our $save_level = 9; our $save_level = 9;
@ -31,7 +31,7 @@ our $fatal_warn = 0;
our $log_file = $0.".log"; our $log_file = $0.".log";
my $log_fd; my $log_fd;
sub log($@) sub log
{ {
my $level = shift; my $level = shift;
@ -42,7 +42,7 @@ sub log($@)
} }
if (!$log_fd && $log_file) { if (!$log_fd && $log_file) {
open ($log_fd, ">>", $log_file) or die("Unable to open log ($log_file) file for writing"); open ($log_fd, ">>", $log_file) or croak("Unable to open log ($log_file) file for writing");
say $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " START new logging session "; say $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " START new logging session ";
} }
@ -63,18 +63,15 @@ sub log($@)
} }
if ($fatal_warn && $level <= WARN){ if ($fatal_warn && $level <= WARN){
#TODO Thibaut log(INFO, "Program stopped due to warning");
#log(INFO, "Program stopped due to warning");
exit 125; exit 125;
} }
elsif ($fatal_error && $level <= ERROR) { elsif ($fatal_error && $level <= ERROR) {
#TODO Thibaut log(INFO, "Program stopped due to error");
#log(INFO, "Program stopped due to error");
exit 126; exit 126;
} }
elsif ($level <= FATAL) { elsif ($level <= FATAL) {
#TODO Thibaut log(INFO, "Program stopped due to fatal error");
#log(INFO, "Program stopped due to fatal error");
exit 127; exit 127;
} }
} }
@ -84,7 +81,8 @@ sub levelstr($)
my $level = shift; my $level = shift;
return "FATAL" if ($level == 1); return "FATAL" if ($level == 1);
return "ERROR" if ($level == 3 or $level == 2); return "ALERT" if ($level == 2);
return "ERROR" if ($level == 3);
return "WARN " if ($level == 4); return "WARN " if ($level == 4);
return "DONE " if ($level == 5); return "DONE " if ($level == 5);
return "USAGE" if ($level == 6); return "USAGE" if ($level == 6);