Certainly an inefficient, unwieldy solution if you're dealing
with huge logfiles.  May be problematic on non-Unix too
but you could post-process the logfile in an END {} block


eg, get rid of hr:min:ss part of timestamp for example:

END {
    $^I = '';
    @ARGV = qw( /path/to/error.log);
    while (<>) { s/\d\d:\d\d:\d\d//; print }
}




On Sat, 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.
>
>         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.
>
> Thanks,
> Frank
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>

--
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