Perl - log with finer timestaps (milliseconds)

From Skytech
Revision as of 08:26, 13 October 2008 by 80.166.222.82 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Create the logger subrutine and just call it with &logStuff(...)

And remember to add the needed module in the top!!

use Time::HiRes qw ( gettimeofday );

[....]

sub logStuff
{
        my $sFile = '/usr/lib/postgresql/8.3/bin/logs/sync_timer.log';
        my $sData = shift;
        open (debuglogger, ">>$sFile");
        my ($s, $usec) = gettimeofday();
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
        print debuglogger "$hour:$min:$sec.$usec:\t$sData\n";
        close (debuglogger);
}