package NewError; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter AutoLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw(log_error std_log_error); #$VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/; $VERSION = '0.01'; # Define global variables use vars qw( $curr_dir $work_file $log_file $std_log_file); #--------------------------------------------------------------------------------- # Grab the current directory from $0. The following regular expression # looks for 'CURR_DIR\xxxxx.xxx' or 'CURR_DIR/xxxxx.xxx'. Place it in # the BEGIN block so we can use it to include modules #--------------------------------------------------------------------------------- BEGIN { $0 =~ '(.*[\\\/])\w+\.\w+$'; $curr_dir = $1 || "./"; } sub log_error{ # Set up error log file $log_file = "error_log.txt"; use CGI::Carp qw(carpout); open(LOG, ">>${curr_dir}${log_file}") or die "Unable to append to error log: $!"; carpout(*LOG); } ##### End Sub log_error sub std_log_error{ #This will log general errors generated as example by user interaction my @data = @_; $std_log_file = "error_log_std.txt"; my ( $year, $mon, $day, $hr, $min, $sec) = Today_and_Now(); my $timestamp = sprintf "%02d-%02d-%02d:%02d:%02d:%02d ", $mon, $day, ($year - 2000), $hr, $min, $sec; open(LOG_FILE, ">>${curr_dir}${std_log_file}") or die "Unable to append to error log: $!"; print LOG_FILE $timestamp, @data, "\n"; close( LOG_FILE ); } #### End Sub std_log_error 1; __END__