From a9071cd1c10bcf3a2203a28cdbdf0a26b4db8641 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 31 Jul 2015 22:41:24 +0200 Subject: Log high precision timestamps in the logfile. Also, don't try to import POSIX or Time::HiRes unless the logfile is configured. --- imapsync | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'imapsync') diff --git a/imapsync b/imapsync index 30982af..a007089 100755 --- a/imapsync +++ b/imapsync @@ -27,7 +27,6 @@ use Getopt::Long qw/:config posix_default no_ignore_case gnu_compat bundling auto_version/; use DBI (); use List::Util 'first'; -use POSIX 'strftime'; use lib 'lib'; use Net::IMAP::Sync qw/read_config compact_set $IMAP_text $IMAP_cond/; @@ -92,6 +91,8 @@ my ($DBFILE, $LOCKFILE, $LOGGER_FD); $LOCKFILE = $DBFILE =~ s/([^\/]+)\z/.$1.lck/r; if (defined $CONF->{_} and defined $CONF->{_}->{logfile}) { + require 'POSIX.pm'; + require 'Time/HiRes.pm'; open $LOGGER_FD, '>>', $CONF->{_}->{logfile} or die "Can't open $CONF->{_}->{logfile}: $!\n"; $LOGGER_FD->autoflush(1); @@ -208,7 +209,8 @@ sub logger($@) { return unless @_ and defined $LOGGER_FD; my $prefix = ''; if ($LOGGER_FD->fileno != fileno STDERR) { - $prefix = strftime "%b %e %H:%M:%S ", localtime; + my ($s, $us) = Time::HiRes::gettimeofday(); + $prefix = POSIX::strftime("%b %e %H:%M:%S", localtime($s)).".$us "; } $prefix .= "$name: " if defined $name; $LOGGER_FD->say($prefix, @_); -- cgit v1.2.3