Perl - log with finer timestaps (milliseconds)

From Skytech
Jump to: navigation, 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);
}