> On Mar 25, 2017, at 8:51 AM, SSC_perl <p...@surfshopcart.com> wrote:
> 
>       I’ll sometimes use the following code at the beginning of a script to 
> log errors while testing:
> 
> BEGIN {
>       use CGI::Carp qw(carpout);
>       open(_STDERR,'>&STDERR'); close STDERR;
>       open (my $log, '>>', 'logs/error.log') or warn("Couldn't open 
> error.log: $! \n");
>       carpout($log);
>       close ($log);
> }
> 
>       However, I would like to change the date format.  I’m not wild about 
> seeing the the full timestamp on every line:
> 
> [Sat Mar 25 08:05:58 2017]
> 
>       Is there a way I can format that to my liking?  I see there's a 
> ‘noTimestamp’ option to stop it from printing altogether, but I don’t see a 
> way to change the output.

The timestamp is generated in the stamp() function, which starts on line 387 of 
the source file Carp.pm. You can copy the source of the modules and edit the 
stamp function to generate a shorter timestamp. You could also try overriding 
the supplied function of the imported module with your own version (not sure 
exactly how that is done).

> 
>       Side question: is there a better way to accomplish what I’m doing 
> above?  I’m happy with what I already have (except for the date) but only 
> because I don’t know anything else.  I’d like to hear how others do this.

I usually write my own log files using normal file output functions. However, 
that is harder, but not impossible, when you are writing CGI programs.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to