diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2015-07-31 22:41:24 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-07-31 22:43:15 +0200 |
commit | a9071cd1c10bcf3a2203a28cdbdf0a26b4db8641 (patch) | |
tree | be0b4397a6e95f38a3de99cb31d8dcb30d5004e5 | |
parent | 69502140d2e229a314bb1eb192d31b9a2c14f981 (diff) |
Log high precision timestamps in the logfile.
Also, don't try to import POSIX or Time::HiRes unless the logfile is
configured.
-rwxr-xr-x | imapsync | 6 | ||||
-rw-r--r-- | lib/Net/IMAP/Sync.pm | 9 |
2 files changed, 11 insertions, 4 deletions
@@ -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, @_); diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm index b44f0a6..4a9d431 100644 --- a/lib/Net/IMAP/Sync.pm +++ b/lib/Net/IMAP/Sync.pm @@ -23,7 +23,6 @@ use strict; use Config::Tiny (); use IO::Select (); use List::Util 'first'; -use POSIX 'strftime'; use Socket 'SO_KEEPALIVE'; use Exporter 'import'; @@ -288,6 +287,11 @@ sub new($%) { # are considered. $self->{_MODIFIED} = {}; + if (defined $self->{'logger-fd'} and $self->{'logger-fd'}->fileno != fileno STDERR) { + require 'POSIX.pm'; + require 'Time/HiRes.pm'; + } + # wait for the greeting my $x = $self->_getline(); $x =~ s/\A\* (OK|PREAUTH) // or $self->panic($x); @@ -402,7 +406,8 @@ sub logger($@) { return unless @_ and defined $self->{'logger-fd'}; my $prefix = ''; if ($self->{'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 .= defined "$self->{name}" ? $self->{name} : ''; $prefix .= "($self->{_SELECTED})" if $self->{_STATE} eq 'SELECTED'; |