in reply to Re: formatting STDOUT
in thread formatting STDOUT

Hi, this code looks interesting, but I can't seem to figure out how to make it work. Could you please post a simple working example using it? Thanks.

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^3: formatting STDOUT
by salva (Canon) on May 31, 2005 at 20:14 UTC
    well, it's very simple to use, after it is called on a perl script, every line written to STDOUT will get the datestamp prepended.

    for instance, create a module like:

    package MyApp::Logger; select STDOUT; $|=1; unless (open STDOUT, '|-') { eval { while(<>) { print scalar(localtime), ' ', $_; } }; exit(0); } 1;
    and then from your script, just use the module, and then print whatever you want:
    #!/usr/bin/perl use MyApp::Logger; print "foo\nbar\n";