diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2015-08-09 20:41:59 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-08-09 20:41:59 +0200 |
commit | c1549a74c99904fb2648240cab239d61ab0c9522 (patch) | |
tree | 37c574fb46e5c924c5059d49570987f635e7b060 /imapsync | |
parent | 8f56dacdbc3459959b3200e776387d34f91e968c (diff) | |
parent | b1985240f59a22b27824c9fdcb79998a1c7c0396 (diff) |
Merge branch 'master' into debian
Diffstat (limited to 'imapsync')
-rwxr-xr-x | imapsync | 14 |
1 files changed, 11 insertions, 3 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,10 +91,15 @@ 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); } + elsif ($CONFIG{debug}) { + $LOGGER_FD = \*STDERR; + } } my $DBH; @@ -196,14 +200,18 @@ $DBH->do('PRAGMA foreign_keys = ON'); sub msg($@) { my $name = shift; return unless @_; - logger($name, @_) if defined $LOGGER_FD and $LOGGER_FD ne \*STDERR; + logger($name, @_) if defined $LOGGER_FD and $LOGGER_FD->fileno != fileno STDERR; my $prefix = defined $name ? "$name: " : ''; print STDERR $prefix, @_, "\n"; } sub logger($@) { my $name = shift; return unless @_ and defined $LOGGER_FD; - my $prefix = strftime "%b %e %H:%M:%S ", localtime; + my $prefix = ''; + if ($LOGGER_FD->fileno != fileno STDERR) { + 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, @_); } |