aboutsummaryrefslogtreecommitdiffstats
path: root/imapsync
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-07-31 22:40:28 +0200
committerGuilhem Moulin <guilhem@fripost.org>2015-07-31 22:40:30 +0200
commit69502140d2e229a314bb1eb192d31b9a2c14f981 (patch)
tree75ba8c76a9f2c1d130107e404da5530f79004850 /imapsync
parent74ef024258870c9f767688f9305c1fab3e4ce393 (diff)
Log debug messages to STDERR unless 'logfile' is set.
However don't include timestamps to STDERR, that's the job of the syslog.
Diffstat (limited to 'imapsync')
-rwxr-xr-ximapsync10
1 files changed, 8 insertions, 2 deletions
diff --git a/imapsync b/imapsync
index b0226c3..30982af 100755
--- a/imapsync
+++ b/imapsync
@@ -96,6 +96,9 @@ my ($DBFILE, $LOCKFILE, $LOGGER_FD);
or die "Can't open $CONF->{_}->{logfile}: $!\n";
$LOGGER_FD->autoflush(1);
}
+ elsif ($CONFIG{debug}) {
+ $LOGGER_FD = \*STDERR;
+ }
}
my $DBH;
@@ -196,14 +199,17 @@ $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) {
+ $prefix = strftime "%b %e %H:%M:%S ", localtime;
+ }
$prefix .= "$name: " if defined $name;
$LOGGER_FD->say($prefix, @_);
}