36 # get a timestamp in the format YYYYMMDDHMS 37 my ($year, $month, $dayofmonth, $hour, $minute, $second) 38 = (localtime())[5, 4, 3, 2, 1, 0]; #### # get a timestamp in the format YYYYMMDDHMS my ( $second, $minute, $hour, $dayofmonth, $month, $year ) = localtime; #### 70 parse_config($path_to_conf_file) if $path_to_conf_file; 100 # declare LOG file handle 101 my $LOG; 102 sysopen ($LOG, $path_to_log_file, O_WRONLY | O_APPEND | O_CREAT) 103 or die "Can't open $path_to_log_file: $!"; 104 # We'll try and keep a lock on the log file for the duration of our script 105 flock($LOG, LOCK_EX) or die "Can't get a lock on $path_to_log_file"; 201 if (/^log-file\s*=\s*(.+)$/) { 202 if (-d $1) { 203 warn "in $conf_filename line $.: $1 is a directory"; 204 next; 205 } 206 unless (-e $1) { 207 unless (open(LOG, ">", $1)) { 208 warn "in $conf_filename line $.: Cannot open $1 for writing: $!"; 209 next; 210 } 211 print LOG "[" . scalar(localtime()) . "] Created logfile\n"; 212 } 213 close(LOG); 214 $path_to_log_file = $1; 215 next; 216 } #### 268 sub logger { 269 my ($message, $level) = @_; 270 return if $level > $log_level; 271 272 # name log levels 273 my @level_names = qw( NONE ERROR WARNING INFO DEBUG ); 274 275 # autoflush output for current scope only 276 local $| = 1; 277 278 # DEBUG 279 #print "\@level_names:\n"; 280 #print "\t$_\n" foreach @level_names; 281 #print "\$level: $level\n"; 282 #print "\$message: $message\n"; 283 284 print $LOG "[" . scalar(localtime()) . "] " . $level_names[$level] . ": $message\n"; 285 } #### syswrite $LOG "[" . scalar(localtime()) . "] " . $level_names[$level] . ": $message\n"; #### 202 if (-d $1) { 203 warn "in $conf_filename line $.: $1 is a directory"; 204 next; 205 } 206 unless (-e $1) { 218 if (-d $1) { 219 warn "in $conf_filename line $.: $1 is a directory"; 220 next; 221 } 222 unless (-e $1) { #### 202 if (-d $1) { 203 warn "in $conf_filename line $.: $1 is a directory"; 204 next; 205 } 206 unless (-e _) { 218 if (-d $1) { 219 warn "in $conf_filename line $.: $1 is a directory"; 220 next; 221 } 222 unless (-e _) {