in reply to Using STDERR and timestamps to write to a log file
You can also do further processing of the output easily. For example, the code below copies STDERR to some file while adding a timestamp and removing ANSI color escape sequences from the data.
$0=~m|([^/]*)$|; my $name=$1; our $filename="/tmp/debug-$name.out"; my $pid=open STDERR, "|-"; if (defined $pid and $pid==0) { print "writing output to $filename\n"; open (TEE,">$filename"); select TEE; $|=1; print TEE "$0 started at ".`date`."\n"; select STDERR; my $ESC=quotemeta "\033["; while(<STDIN>) { my $line=$_; my ($sec, $min, $hour)=gmtime; print STDERR $line; $line=~s|$ESC.*?m||go; printf TEE "%02d:%02d:%02d| %s",$hour,$min,$sec,$line; } exit(0); }
|
|---|