Perl - log with finer timestaps (milliseconds)

From Skytech
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


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);
}