Commit c99ddcbd authored by sikeda's avatar sikeda
Browse files

[dev] Now executables under sbindir use Sympa::Log instead of Log.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12024 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 8d88504a
This diff is collapsed.
This diff is collapsed.
......@@ -38,7 +38,7 @@ use Sympa::Constants;
use Sympa::Crash; # Show traceback.
use Sympa::DatabaseManager;
use Sympa::List;
use Log;
use Sympa::Log;
use Sympa::Mailer;
use Sympa::Message;
use tools;
......@@ -86,7 +86,7 @@ unless (Conf::load()) {
Conf::get_sympa_conf();
}
Log::do_openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
my $mailer = Sympa::Mailer->instance;
......@@ -99,16 +99,16 @@ $mailer->{log_smtp} = $default_log_smtp;
my $default_log_level;
if ($main::options{'log_level'}) {
$default_log_level = $main::options{'log_level'};
Log::set_log_level($default_log_level);
Log::do_log(
$log->{level} = $default_log_level;
$log->syslog(
'info',
'Configuration file read, log level set using options: %s',
$main::options{'log_level'}
);
} else {
$default_log_level = $Conf::Conf{'log_level'};
Log::set_log_level($default_log_level);
Log::do_log(
$log->{level} = $default_log_level;
$log->syslog(
'info',
'Configuration file read, default log level %s',
$Conf::Conf{'log_level'}
......@@ -128,14 +128,14 @@ unless ($main::options{'debug'} || $main::options{'foreground'}) {
setpgrp 0, 0;
my $child_pid = fork;
if ($child_pid) {
Log::do_log('info', 'Starting bulk master daemon, PID %s',
$log->syslog('info', 'Starting bulk master daemon, PID %s',
$child_pid);
exit 0;
} elsif (not defined $child_pid) {
die sprintf 'Cannot fork: %s', $ERRNO;
}
}
Log::do_openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
## If process is running in foreground, don't write STDERR to a dedicated file
my $options;
$options->{'stderr_to_tty'} = 1 if ($main::options{'foreground'});
......@@ -169,7 +169,7 @@ unless (chdir($Conf::Conf{'home'})) {
die sprintf 'Can\'t chdir to %s: %s', $Conf::Conf{'home'}, $!;
}
Log::do_log('notice', 'Bulk %s Started', Sympa::Constants::VERSION);
$log->syslog('notice', 'Bulk %s Started', Sympa::Constants::VERSION);
## Catch signals, in order to exit cleanly, whenever possible.
$SIG{'TERM'} = 'sigterm';
......@@ -189,7 +189,7 @@ while (!$end) {
# Enable SMTP logging if required.
$mailer->{log_smtp} = $default_log_smtp;
# setting log_level using conf unless it is set by calling option
Log::set_log_level($default_log_level);
$log->{level} = $default_log_level;
Sympa::List::init_list_cache();
# Process grouped notifications
......@@ -221,14 +221,14 @@ while (!$end) {
my @pids_leftover = keys %dead_children;
if ($#pids_leftover > -1) {
my @dc;
Log::do_log('debug2',
$log->syslog('debug2',
'Some childs of current process disappeared. Checking whether they shut down cleanly or not.'
);
my $pids_in_pfile =
Sympa::Tools::Daemon::get_pids_in_pid_file('bulk');
foreach my $fpid (@{$pids_in_pfile}) {
if (defined $dead_children{$fpid}) {
Log::do_log(
$log->syslog(
'err',
'The %s child exists in the PID file but is no longer running. Removing it and notyfying listmaster',
$fpid
......@@ -263,7 +263,7 @@ while (!$end) {
Sympa::DatabaseManager->disconnect;
if ($Conf::Conf{'bulk_max_count'} > 1) {
Log::do_log(
$log->syslog(
'info',
'Important workload: %s packets to process. Creating %s child bulks to increase sending rate',
$r_packets,
......@@ -273,10 +273,10 @@ while (!$end) {
for my $process_count (
1 .. $Conf::Conf{'bulk_max_count'} -
scalar(@remaining_children)) {
Log::do_log('info', "Will fork: %s", $process_count);
$log->syslog('info', "Will fork: %s", $process_count);
my $child_pid = fork;
if ($child_pid) {
Log::do_log('info',
$log->syslog('info',
'Starting bulk child daemon, PID %s',
$child_pid);
# Saves the pid number
......@@ -285,7 +285,7 @@ while (!$end) {
$created_children{$child_pid} = 1;
sleep 1;
} elsif (not defined $child_pid) {
Log::do_log('err', 'Cannot fork: %m');
$log->syslog('err', 'Cannot fork: %m');
last;
} else {
## We're in a child bulk process
......@@ -294,9 +294,9 @@ while (!$end) {
('pid' => $PID));
$date_of_last_activity = time();
$main::daemon_usage = 'DAEMON_SLAVE'; # child bulk
Log::do_openlog($Conf::Conf{'syslog'},
$log->openlog($Conf::Conf{'syslog'},
$Conf::Conf{'log_socket_type'}, 'bulk');
Log::do_log('info',
$log->syslog('info',
'Bulk slave daemon started with PID %s',
$PID);
last;
......@@ -316,7 +316,7 @@ while (!$end) {
if ( $main::daemon_usage eq 'DAEMON_SLAVE'
and time() - $date_of_last_activity > $Conf::Conf{'bulk_lazytime'}
and !(my $r_packets = $bulk->too_much_remaining_packets())) {
Log::do_log('info',
$log->syslog('info',
'Process %s didn\'t send any message since %s seconds, exiting',
$PID, $Conf::Conf{'bulk_lazytime'});
last;
......@@ -338,7 +338,7 @@ while (!$end) {
}
if ($message->{serial} eq '0' or $message->{serial} eq 's') {
Log::do_log(
$log->syslog(
'notice',
'Start sending message %s to %s (priority %s) (starting %s seconds after scheduled expedition date)',
$message,
......@@ -354,8 +354,8 @@ while (!$end) {
|| Sympa::Tools::Data::smart_eq(
Conf::get_robot_conf($robot, 'log_smtp'), 'on');
# setting log_level using conf unless it is set by calling option
Log::set_log_level(
(defined $main::options{'log_level'})
$log->{level} = (
defined $main::options{'log_level'}
? $main::options{'log_level'}
: Conf::get_robot_conf($robot, 'log_level')
);
......@@ -448,7 +448,7 @@ while (!$end) {
if ($new_message->{shelved}{merge}) {
unless ($new_message->personalize($list, $rcpt)) {
Log::do_log('err', 'Erreur d appel personalize()');
$log->syslog('err', 'Erreur d appel personalize()');
tools::send_notify_to_listmaster($list, 'bulk_failed',
{'message_id' => $message->get_id});
# Quarantine packet into bad spool.
......@@ -465,7 +465,7 @@ while (!$end) {
if ($new_message->{shelved}{smime_encrypt}) {
unless ($new_message->smime_encrypt($rcpt)) {
Log::do_log(
$log->syslog(
'err',
'Unable to encrypt message %s from %s for recipient %s',
$new_message,
......@@ -504,7 +504,7 @@ while (!$end) {
tag => $new_message->{serial}
)
) {
Log::do_log('err',
$log->syslog('err',
'Failed to store message %s into mailer',
$new_message);
$bulk->quarantine($handle);
......@@ -553,7 +553,7 @@ while (!$end) {
$new_message, [@rcpts], tag => $new_message->{serial}
)
) {
Log::do_log('err', 'Failed to store message %s into mailer',
$log->syslog('err', 'Failed to store message %s into mailer',
$new_message);
$bulk->quarantine($handle);
undef $handle;
......@@ -563,14 +563,15 @@ while (!$end) {
## Remove packet once it has been processed
if ($handle) {
unless ($bulk->remove($handle)) {
Log::do_log('err', 'Failed to remove processed packet %s',
$log->syslog('err', 'Failed to remove processed packet %s',
$message);
}
}
$date_of_last_activity = time();
} elsif ($handle) {
Log::do_log('err', 'Cannot parse message <%s>', $handle->basename(1));
$log->syslog('err', 'Cannot parse message <%s>',
$handle->basename(1));
$bulk->quarantine($handle);
next;
} else {
......@@ -583,7 +584,7 @@ while (!$end) {
# Purge grouped notifications
Sympa::Alarm->instance->flush(purge => 1);
Log::do_log('notice', 'Bulk exited normally due to signal');
$log->syslog('notice', 'Bulk exited normally due to signal');
Sympa::Tools::Daemon::remove_pid('bulk', $PID, $options);
exit(0);
......@@ -592,8 +593,8 @@ exit(0);
## variable.
sub sigterm {
my ($sig) = @_;
Log::do_log('notice', 'Signal %s received, still processing current task',
$sig);
$log->syslog('notice',
'Signal %s received, still processing current task', $sig);
$end = 1;
}
......@@ -605,9 +606,9 @@ sub trace_smime {
return if defined $result and $result == 0;
unless ($result) {
Log::do_log('debug', 'Signature S/MIME NOT OK (%s)', $where);
$log->syslog('debug', 'Signature S/MIME NOT OK (%s)', $where);
} else {
Log::do_log('debug', 'Signature S/MIME OK (%s)', $where);
$log->syslog('debug', 'Signature S/MIME OK (%s)', $where);
}
}
......
......@@ -44,7 +44,7 @@ use Sympa::DatabaseManager;
use Sympa::Family;
use Sympa::Language;
use Sympa::List;
use Log;
use Sympa::Log;
use Sympa::Mailer;
use Sympa::Report;
use tools;
......@@ -100,9 +100,9 @@ if ($main::options{'debug'}) {
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'notice,err'
if $main::options{'upgrade'}
|| $main::options{'reload_list_config'}
|| $main::options{'test_database_message_buffer'}
|| $main::options{'conf_2_db'};
|| $main::options{'reload_list_config'}
|| $main::options{'test_database_message_buffer'}
|| $main::options{'conf_2_db'};
if ($main::options{'upgrade_config_location'}) {
my $config_file = Conf::get_sympa_conf();
......@@ -175,7 +175,7 @@ if ($main::options{'upgrade_config_location'}) {
}
## Open the syslog and say we're read out stuff.
Log::do_openlog(
$log->openlog(
$Conf::Conf{'syslog'},
$Conf::Conf{'log_socket_type'},
service => 'sympa/health_check'
......@@ -183,15 +183,15 @@ if ($main::options{'upgrade_config_location'}) {
## Setting log_level using conf unless it is set by calling option
if ($main::options{'log_level'}) {
Log::set_log_level($main::options{'log_level'});
Log::do_log(
$log->{level} = $main::options{'log_level'};
$log->syslog(
'info',
'Configuration file read, log level set using options: %s',
$main::options{'log_level'}
);
} else {
Log::set_log_level($Conf::Conf{'log_level'});
Log::do_log(
$log->{level} = $Conf::Conf{'log_level'};
$log->syslog(
'info',
'Configuration file read, default log level %s',
$Conf::Conf{'log_level'}
......@@ -241,7 +241,7 @@ my $mailer = Sympa::Mailer->instance;
_load();
Log::do_openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
# Set the User ID & Group ID for the process
$GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2];
......@@ -263,7 +263,7 @@ unless (($GID == (getgrnam(Sympa::Constants::GROUP))[2])
umask(oct($Conf::Conf{'umask'}));
## Most initializations have now been done.
Log::do_log('notice', 'Sympa %s Started', Sympa::Constants::VERSION());
$log->syslog('notice', 'Sympa %s Started', Sympa::Constants::VERSION());
# Check for several files.
#FIXME: This would be done in --health_check mode.
......@@ -282,7 +282,7 @@ if ($main::options{'dump'}) {
## The parameter can be a list address
unless ($main::options{'dump'} =~ /\@/) {
Log::do_log('err', 'Incorrect list address %s',
$log->syslog('err', 'Incorrect list address %s',
$main::options{'dump'});
exit;
......@@ -290,7 +290,7 @@ if ($main::options{'dump'}) {
my $list = Sympa::List->new($main::options{'dump'});
unless (defined $list) {
Log::do_log('err', 'Unknown list %s', $main::options{'dump'});
$log->syslog('err', 'Unknown list %s', $main::options{'dump'});
exit;
}
......@@ -386,7 +386,7 @@ if ($main::options{'dump'}) {
## The parameter should be a list address
unless ($main::options{'import'} =~ /\@/) {
Log::do_log(
$log->syslog(
'err',
'Incorrect list address %s',
$main::options{'import'}
......@@ -395,7 +395,7 @@ if ($main::options{'dump'}) {
}
unless ($list = Sympa::List->new($main::options{'import'})) {
Log::do_log('err', 'Unknown list name %s', $main::options{'import'});
$log->syslog('err', 'Unknown list name %s', $main::options{'import'});
exit 1;
}
......@@ -774,29 +774,29 @@ if ($main::options{'dump'}) {
## Migration from one version to another
} elsif ($main::options{'upgrade'}) {
Log::do_log('notice', "Upgrade process...");
$log->syslog('notice', "Upgrade process...");
$main::options{'from'} ||= Sympa::Upgrade::get_previous_version();
$main::options{'to'} ||= Sympa::Constants::VERSION;
if ($main::options{'from'} eq $main::options{'to'}) {
Log::do_log('err', 'Current version: %s; no upgrade is required',
$log->syslog('err', 'Current version: %s; no upgrade is required',
$main::options{'to'});
exit 0;
} else {
Log::do_log('notice', "Upgrading from %s to %s...",
$log->syslog('notice', "Upgrading from %s to %s...",
$main::options{'from'}, $main::options{'to'});
}
unless (
Sympa::Upgrade::upgrade($main::options{'from'}, $main::options{'to'}))
{
Log::do_log('err', "Migration from %s to %s failed",
$log->syslog('err', "Migration from %s to %s failed",
$main::options{'from'}, $main::options{'to'});
exit 1;
}
Log::do_log('notice', 'Upgrade process finished');
$log->syslog('notice', 'Upgrade process finished');
Sympa::Upgrade::update_version();
exit 0;
......@@ -805,20 +805,20 @@ if ($main::options{'dump'}) {
## versions
} elsif ($main::options{'upgrade_shared'}) {
Log::do_log('notice', "Upgrade shared process...");
$log->syslog('notice', "Upgrade shared process...");
my $listname;
my $robot;
unless (($main::options{'list'}) || ($main::options{'robot'})) {
Log::do_log('err',
$log->syslog('err',
"listname and domain are required, use --list= --robot= options");
exit 0;
}
$listname = $main::options{'list'};
$robot = $main::options{'robot'};
Log::do_log('notice', "Upgrading share for list=%s robot=%s",
$log->syslog('notice', "Upgrading share for list=%s robot=%s",
$listname, $robot);
my $list = Sympa::List->new($listname, $robot);
......@@ -830,7 +830,7 @@ if ($main::options{'dump'}) {
}
if (-d $list->{'dir'} . '/shared') {
Log::do_log(
$log->syslog(
'notice',
'Processing list %s...',
$list->get_list_address()
......@@ -850,17 +850,17 @@ if ($main::options{'dump'}) {
$list_encoding);
if ($count) {
Log::do_log('notice', 'List %s: %d filenames has been changed',
$log->syslog('notice', 'List %s: %d filenames has been changed',
$list->{'name'}, $count);
}
}
Log::do_log('notice', 'Upgrade_shared process finished');
$log->syslog('notice', 'Upgrade_shared process finished');
exit 0;
} elsif ($main::options{'reload_list_config'}) {
if ($main::options{'list'}) {
Log::do_log('notice', 'Loading list %s...', $main::options{'list'});
$log->syslog('notice', 'Loading list %s...', $main::options{'list'});
my $list =
Sympa::List->new($main::options{'list'}, '',
{'reload_config' => 1});
......@@ -870,10 +870,10 @@ if ($main::options{'dump'}) {
exit 1;
}
} else {
Log::do_log('notice', "Loading ALL lists...");
$log->syslog('notice', "Loading ALL lists...");
my $all_lists = Sympa::List::get_lists('*', 'reload_config' => 1);
}
Log::do_log('notice', '...Done.');
$log->syslog('notice', '...Done.');
exit 0;
}
......@@ -1009,7 +1009,7 @@ sub _load {
}
## Open the syslog and say we're read out stuff.
Log::do_openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
# Enable SMTP logging if required
$mailer->{log_smtp} = $main::options{'mail'}
......@@ -1017,15 +1017,15 @@ sub _load {
# setting log_level using conf unless it is set by calling option
if (defined $main::options{'log_level'}) {
Log::set_log_level($main::options{'log_level'});
Log::do_log(
$log->{level} = $main::options{'log_level'};
$log->syslog(
'info',
'Configuration file read, log level set using options: %s',
$main::options{'log_level'}
);
} else {
Log::set_log_level($Conf::Conf{'log_level'});
Log::do_log(
$log->{level} = $Conf::Conf{'log_level'};
$log->syslog(
'info',
'Configuration file read, default log level %s',
$Conf::Conf{'log_level'}
......@@ -1087,7 +1087,7 @@ sub _load {
#
##############################################################
sub SendDigest {
Log::do_log('debug', '(%s => %s, %s => %s)', @_);
$log->syslog('debug', '(%s => %s, %s => %s)', @_);
my %options = @_;
my $keep_digest = $options{keep_digest};
my $send_now = $options{send_now};
......@@ -1126,22 +1126,20 @@ sub SendDigest {
unless ($metadata and ref($metadata->{context}) eq 'Sympa::List') {
#FIXME: File would be kept in such as bad/ directory.
Log::do_log('info', 'Unknown list %s, deleting digest file',
$log->syslog('info', 'Unknown list %s, deleting digest file',
$listaddress);
Log::db_log(
{ #'robot' => $robot,
#'list' => $list->{'name'},
'action' => 'SendDigest',
'parameters' => "$filename",
'target_email' => '',
'msg_id' => '',
'status' => 'error',
'error_type' => 'unknown_list',
'user_email' => '',
}
$log->db_log( #'robot' => $robot,
#'list' => $list->{'name'},
'action' => 'SendDigest',
'parameters' => "$filename",
'target_email' => '',
'msg_id' => '',
'status' => 'error',
'error_type' => 'unknown_list',
'user_email' => ''
);
unlink $filename;
next; # foreach my $listaddress
next; # foreach my $listaddress
}
my $list = $metadata->{context};
my $robot_id = $list->{'domain'};
......@@ -1154,23 +1152,22 @@ sub SendDigest {
if ($send_now or $list->get_nextdigest()) {
## Blindly send the message to all users.
Log::do_log('info', "Sending digest to list %s", $listaddress);
$log->syslog('info', "Sending digest to list %s", $listaddress);
my $start_time = time;
$list->distribute_digest(keep_digest => $keep_digest);
Log::do_log('info', 'Digest of the list %s sent (%d seconds)',
$log->syslog('info', 'Digest of the list %s sent (%d seconds)',
$list, time - $start_time);
Log::db_log(
{ 'robot' => $robot_id,
'list' => $list->{'name'},
'action' => 'SendDigest',
'parameters' => "",
'target_email' => '',
'msg_id' => '',
'status' => 'success',
'error_type' => '',
'user_email' => '',
}
$log->db_log(
'robot' => $robot_id,
'list' => $list->{'name'},
'action' => 'SendDigest',
'parameters' => "",
'target_email' => '',
'msg_id' => '',
'status' => 'success',
'error_type' => '',
'user_email' => ''
);
}
}
......
......@@ -40,7 +40,7 @@ use Sympa::DatabaseManager;
use Sympa::Family;
use Sympa::List;
use Sympa::LockedFile;
use Log;
use Sympa::Log;
use Sympa::Mailer;
use Sympa::Message;
use Sympa::Report;
......@@ -100,7 +100,7 @@ unless ($main::options{'foreground'}) {
my $child_pid = fork;
if ($child_pid) {
Log::do_log('notice', 'Starting sympa/automatic daemon, PID %d',
$log->syslog('notice', 'Starting sympa/automatic daemon, PID %d',
$child_pid);
exit 0;
} elsif (not defined $child_pid) {
......@@ -111,7 +111,7 @@ unless ($main::options{'foreground'}) {
my $pidfile = 'sympa_automatic';
Log::do_openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
$log->openlog($Conf::Conf{'syslog'}, $Conf::Conf{'log_socket_type'});
# If process is running in foreground, don't write STDERR to a
# dedicated file
......@@ -142,7 +142,7 @@ unless (($GID == (getgrnam(Sympa::Constants::GROUP))[2])
umask(oct($Conf::Conf{'umask'}));
## Most initializations have now been done.
Log::do_log(
$log->syslog(
'notice',
'Sympa/automatic %s Started',
Sympa::Constants::VERSION()
......@@ -153,14 +153,14 @@ sleep 1; ## wait until main process has created required directories
## Do we have right access in the directory
if ($main::options{'keepcopy'}) {
if (!-d $main::options{'keepcopy'}) {
Log::do_log(
$log->syslog(
'notice',
'Cannot keep a copy of incoming messages: %s is not a directory',
$main::options{'keepcopy'}
);
delete $main::options{'keepcopy'};
} elsif (!-w $main::options{'keepcopy'}) {
Log::do_log(
$log->syslog(
'notice',
'Cannot keep a copy of incoming messages: no write access to %s',
$main::options{'keepcopy'}
......@@ -233,7 +233,7 @@ while ($signal ne 'term') {
my $status = process_message($message);
if (defined $status) {
Log::do_log('debug', "Finished %s", $message);
$log->syslog('debug', "Finished %s", $message);
if ($main::options{'keepcopy'}) {
unless (
......@@ -242,7 +242,7 @@ while ($signal ne 'term') {
$main::options{'keepcopy'} . '/' . $filename
)
) {
Log::do_log(
$log->syslog(