Commit 346eca48 authored by sikeda's avatar sikeda
Browse files

[dev] Global variable %main::options no longer is referred by Log module. ...

[dev] Global variable %main::options no longer is referred by Log module.  Instead, {log_to_stderr} property of Sympa::Log instance would be set.

As a side work, set_log_level() was obsoleted and {level} property will be used.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12008 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 77e5b5bc
......@@ -78,9 +78,9 @@ sub get_next_db_log {
return Sympa::Log->instance->get_next_db_log(@_);
}
# OBSOLETED. Use Sympa::Log::set_level().
# OBSOLETED. Use {level} property of Sympa::Log instance.
sub set_log_level {
return Sympa::Log->instance->set_level(@_);
Sympa::Log->instance->{level} = shift;
}
#OBSOLETED: No longer used.
......
......@@ -37,15 +37,9 @@ use base qw(Class::Singleton);
# Constructor for Class::Singleton.
sub _new_instance {
my $class = shift;
my @options = @_;
my $class = shift;
my $self = bless {} => $class;
if (@options) {
return $self->openlog(@options);
} else {
return $self;
}
bless {} => $class;
}
# Old name: Log::do_openlog().
......@@ -99,8 +93,8 @@ sub syslog {
}
# do not log if log level is too high regarding the log requested by user
return if defined $self->{_level} and $levels{$level} > $self->{_level};
return if !defined $self->{_level} and $levels{$level} > 0;
return if defined $self->{level} and $levels{$level} > $self->{level};
return if !defined $self->{level} and $levels{$level} > 0;
## Do not display variables which are references.
my @param = ();
......@@ -127,7 +121,7 @@ sub syslog {
## If in 'err' level, build a stack trace,
## except if syslog has not been setup yet.
if (defined $self->{_level} and $level eq 'err') {
if (defined $self->{level} and $level eq 'err') {
my $go_back = 0;
my @calls;
......@@ -181,15 +175,15 @@ sub syslog {
}
## Output to STDERR if needed
if ( !defined $self->{_level}
or ($main::options{'foreground'} and $main::options{'log_to_stderr'})
or ( $main::options{'foreground'}
and $main::options{'batch'}
and $level eq 'err')
if (not defined $self->{level}
or ($self->{log_to_stderr}
and ($self->{log_to_stderr} eq 'all'
or 0 <= index($self->{log_to_stderr}, $level))
)
) {
print STDERR "$message\n";
}
return unless defined $self->{_level};
return unless defined $self->{level};
# Output to syslog
# Note: Sys::Syslog <= 0.07 which are bundled in Perl <= 5.8.7 pass
......@@ -453,17 +447,16 @@ sub get_first_db_log {
);
my $statement =
sprintf
q{SELECT date_logs, robot_logs AS robot, list_logs AS list,
action_logs AS action,
parameters_logs AS parameters,
target_email_logs AS target_email,
msg_id_logs AS msg_id, status_logs AS status,
error_type_logs AS error_type,
user_email_logs AS user_email,
client_logs AS client, daemon_logs AS daemon
FROM logs_table
WHERE robot_logs = %s }, $sdm->quote($select->{'robot'});
sprintf q{SELECT date_logs, robot_logs AS robot, list_logs AS list,
action_logs AS action,
parameters_logs AS parameters,
target_email_logs AS target_email,
msg_id_logs AS msg_id, status_logs AS status,
error_type_logs AS error_type,
user_email_logs AS user_email,
client_logs AS client, daemon_logs AS daemon
FROM logs_table
WHERE robot_logs = %s }, $sdm->quote($select->{'robot'});
#if a type of target and a target are specified
if (($select->{'target_type'}) && ($select->{'target_type'} ne 'none')) {
......@@ -553,18 +546,18 @@ sub get_first_db_log {
}
$self->{_sth} = $sth;
my $log = $sth->fetchrow_hashref('NAME_lc');
my $row = $sth->fetchrow_hashref('NAME_lc');
## If no rows returned, return an empty hash
## Required to differenciate errors and empty results
unless ($log) {
unless ($row) {
return {};
}
## We can't use the "AS date" directive in the SELECT statement because
## "date" is a reserved keywork with Oracle
$log->{date} = $log->{date_logs} if defined($log->{date_logs});
return $log;
$row->{date} = $row->{date_logs} if defined $row->{date_logs};
return $row;
}
......@@ -574,25 +567,18 @@ sub get_next_db_log {
my $sth = $self->{_sth};
die 'Bug in logic. Ask developer' unless $sth;
my $log = $sth->fetchrow_hashref('NAME_lc');
my $row = $sth->fetchrow_hashref('NAME_lc');
unless (defined $log) {
unless (defined $row) {
$sth->finish;
delete $self->{_sth};
}
## We can't use the "AS date" directive in the SELECT statement because
## "date" is a reserved keywork with Oracle
$log->{date} = $log->{date_logs} if defined($log->{date_logs});
return $log;
}
# Old name: Log::set_log_level().
sub set_level {
my $self = shift;
$row->{date} = $row->{date_logs} if defined $row->{date_logs};
$self->{_level} = shift;
return $row;
}
# Aggregate data from stat_table to stat_counter_table.
......@@ -769,7 +755,12 @@ Sympa::Log - Logging facility of Sympa
=head1 SYNOPSIS
TBD.
use Sympa::Log;
my $log = Sympa::Log->instance;
$log->openlog($facility, 'inet');
$log->{level} = 0;
$log->syslog('info', '%s: Stat logging', $$);
=head1 DESCRIPTION
......@@ -779,11 +770,10 @@ TBD.
=over
=item instance ( [ $facility, $socket_type, [ options... ] ] )
=item instance ( )
I<Constructor>.
Creates new singleton instance of L<Sympa::Log>.
TBD.
=item openlog ( $facility, $socket_type, [ options ... ] )
......@@ -813,10 +803,6 @@ TBD.
TBD.
=item set_level
TBD.
=item aggregate_data
TBD.
......@@ -827,6 +813,23 @@ TBD.
=back
=head2 Properties
Instance of L<Sympa::Log> has following properties.
=over
=item {level}
Logging level. Integer or C<undef>.
=item {log_to_stderr}
If set, print logs by syslog() to standard error.
Property value may be log level(s) to print or C<'all'>.
=back
=head1 SEE ALSO
L<Sys::Syslog>, L<Sympa::DatabaseManager>.
......
......@@ -63,7 +63,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -72,11 +71,12 @@ if ($main::options{'help'}) {
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
$main::options{'foreground'} = 1 if ($main::options{'debug'});
$main::options{'log_to_stderr'} = 1
if ($main::options{'debug'} || $main::options{'foreground'});
my $log = Sympa::Log->instance;
$log->{'log_to_stderr'} = 'all' if $main::options{'foreground'};
# Load sympa.conf
unless (Conf::load()) {
......
......@@ -92,7 +92,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -101,12 +100,12 @@ if ($main::options{'help'}) {
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
$main::options{'foreground'} = 1 if ($main::options{'debug'});
$main::options{'log_to_stderr'} = 1
if ($main::options{'debug'} || $main::options{'foreground'});
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'foreground'};
# Load sympa.conf
unless (Conf::load()) {
......
......@@ -64,7 +64,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -73,12 +72,12 @@ if ($main::options{'help'}) {
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
$main::options{'foreground'} = 1 if ($main::options{'debug'});
$main::options{'log_to_stderr'} = 1
if ($main::options{'debug'} || $main::options{'foreground'});
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'foreground'};
# Load sympa.conf
unless (Conf::load()) {
......
......@@ -86,23 +86,25 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
printf "Sympa %s\n", Sympa::Constants::VERSION;
exit 0;
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
}
$main::options{'log_to_stderr'} = 1
if ($main::options{'upgrade'}
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{'conf_2_db'};
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
printf "Sympa %s\n", Sympa::Constants::VERSION;
exit 0;
} elsif ($main::options{'upgrade_config_location'}) {
if ($main::options{'upgrade_config_location'}) {
my $config_file = Conf::get_sympa_conf();
if (-f $config_file) {
......
......@@ -64,17 +64,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
}
# Some option force foreground mode
$main::options{'foreground'} = 1
if $main::options{'debug'};
$main::options{'log_to_stderr'} = 1;
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -82,6 +71,14 @@ if ($main::options{'help'}) {
exit 0;
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'foreground'};
my $mailer = Sympa::Mailer->instance;
_load();
......
......@@ -74,17 +74,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
}
# Some option force foreground mode
$main::options{'foreground'} = 1
if $main::options{'debug'};
$main::options{'log_to_stderr'} = 1;
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -92,6 +81,14 @@ if ($main::options{'help'}) {
exit 0;
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'foreground'};
my $default_lang;
my $language = Sympa::Language->instance;
......
......@@ -49,22 +49,20 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
}
# Some option force foreground mode
$main::options{'foreground'} = 1 if $main::options{'debug'} or -t;
$main::options{'log_to_stderr'} = 1
if ($main::options{'debug'} || $main::options{'foreground'});
if ($options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
} elsif ($options{'version'}) {
printf "Sympa %s\n", Sympa::Constants::VERSION;
exit 0;
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
}
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'debug'} or -t;
my $robot_id = $options{'domain'};
# Load configuration
......
......@@ -62,7 +62,6 @@ unless (
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
......@@ -71,12 +70,12 @@ if ($main::options{'help'}) {
}
if ($main::options{'debug'}) {
$main::options{'log_level'} = 2 unless ($main::options{'log_level'});
$main::options{'log_level'} = 2 unless $main::options{'log_level'};
$main::options{'foreground'} = 1;
}
# Some option force foreground mode
$main::options{'foreground'} = 1 if ($main::options{'debug'});
$main::options{'log_to_stderr'} = 1
if ($main::options{'debug'} || $main::options{'foreground'});
my $log = Sympa::Log->instance;
$log->{log_to_stderr} = 'all' if $main::options{'foreground'};
my $adrlist = {};
......@@ -173,8 +172,8 @@ my $spool_task = $Conf::Conf{'queuetask'};
my @tasks; # list of tasks in the spool
# won't execute send_msg and delete_subs commands if true, only log
undef my $log;
#$log = 1;
undef my $log_only;
#$log_only = 1;
## list of list task models
#my @list_models = ('expire', 'remind', 'sync_include');
......@@ -969,7 +968,7 @@ sub send_msg {
foreach my $email (keys %{$Rvars->{$var}}) {
Log::do_log('notice', '--> message sent to %s', $email);
if (!$log) {
unless ($log_only) {
unless (
tools::send_file(
'*', $template, $email, $Rvars->{$var}{$email}
......@@ -985,7 +984,7 @@ sub send_msg {
foreach my $email (keys %{$Rvars->{$var}}) {
Log::do_log('notice', '--> message sent to %s', $email);
if (!$log) {
unless ($log_only) {
unless (
tools::send_file(
$list, $template, $email, $Rvars->{$var}{$email}
......@@ -1169,7 +1168,7 @@ sub delete_subs_cmd {
my $u = $list->delete_list_member(
users => [$email],
operation => 'auto_del'
) unless $log;
) unless $log_only;
Log::do_log('notice', '--> %s deleted', $email);
$selection{$email} = {};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment