timestamp in STDERR output

David Cantrell david at cantrell.org.uk
Thu Jun 29 15:19:29 BST 2006


On Thu, Jun 29, 2006 at 04:02:46PM +0200, Thomas Busch wrote:

> is it possible to redefine STDERR in such a way that
> you get a timestamp at the beginning of each line ?

#!/usr/bin/perl
use strict;
use warnings;

use Tie::STDERR \&timestamper;

sub timestamper {
    local *STDERR;
    untie *STDERR;
    print time().': '.$_[0];
}

warn "now with timestamps!\n";

-- 
David Cantrell | http://www.cantrell.org.uk/david

Computer Science is about lofty design goals and careful algorithmic
optimisation.  Sysadminning is about cleaning up the resulting mess.


More information about the london.pm mailing list