Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
&app_error("test.txt","File Name that created this error: test_mod.pl" +);
#!C:\perl\bin\perl.exe package ErrorModule; # The code in the BEGIN block will be executed very early # on, even before the rest of this script is parsed. BEGIN { # Use the CGI::Carp module and import the carpout() function. use CGI::Carp qw(carpout); #Send warnings and die messages to the browser. carpout(STDOUT); } use 5.008004; use strict; use warnings; #use CGI::Carp qw(carpout); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not expo +rt # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use ErrorMod ':all'; # If you do not need this, moving things directly into @EXPORT or @EXP +ORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT = qw( app_error ); our $VERSION = '0.01'; our $localtime = localtime; #The Cwd module retrives the current working directory. #The safest way to get the current working directory is with #the cwd() function. This funstion is guaranteed to work on ALL #operating systems and should be used in most cases. use Cwd; our $dir = cwd(); # Set up error log file my $log_file = "error_log.txt"; open(LOG, ">>$dir/$log_file") or die "Unable to append to error log: $ +!"; carpout(*LOG); ##### ***subroutine who print in Appplication Specific Error*** sub app_error{ my $log_app = $_[0]; my @data = $_[1]; #Make sure that the filename doesn't have spaces or extensions like ex +e or bat on it, #otherwise it will create file as app_log.txt instead. unless($log_app=~/^[a-zA-Z_]+\.(?!bat$|exe$)[a-zA-Z_]{3}$/gi) { $log_app="app_log.txt" } open(LOGAPP, ">>$dir/$log_app") or die "Unable to append to $log_app: $!"; print LOGAPP "[$localtime] $log_app : @data $!\n"; carpout(*LOGAPP); close LOGAPP or die "Cannot close log file:: $log_app : $!\n"; } 1; __END__
#!/perl/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw(-oldstyle_urls :standard); use ErrorModule; my $empty; # case 1 my $test = "test"; print header(); print "<br> This is a test<br>"; print $test; print $empty; print "<form action=madetofail.pl method=get>"; print "<input type=text><input type=submit value=go>"; &app_error("test.txt","File Name that created this error: test_mod.pl" +); print "after" # left ; out to fail and to log error by ErrorModule
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error Module not working in Browser, Help!
by DungeonKeeper (Novice) on Jan 09, 2006 at 16:21 UTC | |
by Errto (Vicar) on Jan 09, 2006 at 18:01 UTC | |
by Anonymous Monk on Jan 09, 2006 at 18:36 UTC | |
by Errto (Vicar) on Jan 09, 2006 at 20:15 UTC | |
by Anonymous Monk on Jan 09, 2006 at 16:37 UTC | |
|
Re: Error Module not working in Browser, Help!
by DungeonKeeper (Novice) on Jan 10, 2006 at 09:42 UTC |