diff --git a/docs/logging.md b/docs/logging.md index c0c948c..3bfba41 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -67,22 +67,6 @@ run the 'run' files in the ./ and ./log directories. Any log entries emitted will get handled per the instructions in log/run. The default location specified in log/run is log/main/current. -## logging via 'warn' - -Any warnings emitted are sent to logging plugins with a deafult log level of -LOGWARN. Warnings can be sent to plugins with a different log level using a -prefix. For example: - -`warn 'NOTICE: Danger Will Robinson!'` - -Emitting this warning in a plugin is equivalent to using log(): - -`$self->log(LOGNOTICE, 'Danger Will Robinson!')` - -Notably, using 'warn' in a plugin will always result in that warning being -emitted to STDERR when the test suite is executed, wheras messages sent with -log() are not output to the terminal when running the test suite. - ## plugin loglevel Most plugins support a loglevel argument after their config/plugins entry. diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 1847659..39363b6 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -93,25 +93,6 @@ sub log { $self->varlog($trace, join(" ", @log)); } -sub warn_handler { - my $self = shift; - $self->log( $self->warn_level(@_) ); -} - -sub warn_level { - my ( $self, @warnings ) = @_; - my @levels = ( keys %Qpsmtpd::Constants::log_levels, - qw[ LOGWARNING LOGCRITICAL LOGEMERGENCY ] ); - my $levels = join '|', map { s/^LOG//; $_ } @levels; - my $prefix; - $prefix = $1 if $warnings[0] =~ s/^($levels):\s*//; - $prefix = 'WARN' if ! $prefix; - $prefix = 'WARN' if $prefix eq 'WARNING'; - $prefix = 'CRIT' if $prefix eq 'CRITICAL'; - $prefix = 'EMERG' if $prefix eq 'EMERGENCY'; - return log_level("LOG$prefix"), @warnings; -} - sub varlog { my ($self, $trace) = (shift, shift); my ($hook, $plugin, @log); diff --git a/lib/Qpsmtpd/Constants.pm b/lib/Qpsmtpd/Constants.pm index ba317d8..0c9dec7 100644 --- a/lib/Qpsmtpd/Constants.pm +++ b/lib/Qpsmtpd/Constants.pm @@ -3,7 +3,7 @@ use strict; require Exporter; # log levels -our %log_levels = ( +my %log_levels = ( LOGDEBUG => 7, LOGINFO => 6, LOGNOTICE => 5, @@ -54,7 +54,7 @@ sub return_code { sub log_level { my $test = shift; if ($test =~ /^\d+$/) { # need to return the textural form - foreach (sort keys %log_levels) { + foreach (keys %log_levels) { return $_ if $log_levels{$_} =~ /$test/; } } diff --git a/qpsmtpd b/qpsmtpd index 3675829..9a3d75b 100755 --- a/qpsmtpd +++ b/qpsmtpd @@ -17,7 +17,6 @@ delete $ENV{ENV}; $ENV{PATH} = '/bin:/usr/bin:/var/qmail/bin'; my $qpsmtpd = Qpsmtpd::TcpServer->new(); -$SIG{__WARN__} = sub { $qpsmtpd->warn_handler(@_) }; $qpsmtpd->load_plugins(); $qpsmtpd->start_connection(); $qpsmtpd->run(\*STDIN); # pass the "socket" like -prefork/-forkserver diff --git a/qpsmtpd-forkserver b/qpsmtpd-forkserver index b83839b..7cf8982 100755 --- a/qpsmtpd-forkserver +++ b/qpsmtpd-forkserver @@ -180,7 +180,6 @@ if ($PID_FILE) { # Load plugins here my $qpsmtpd = Qpsmtpd::TcpServer->new(); -$SIG{__WARN__} = sub { $qpsmtpd->warn_handler(@_) }; # Drop privileges my (undef, undef, $quid, $qgid) = getpwnam $USER diff --git a/qpsmtpd-prefork b/qpsmtpd-prefork index 3b15116..42784d3 100755 --- a/qpsmtpd-prefork +++ b/qpsmtpd-prefork @@ -290,7 +290,6 @@ sub run { # setup qpsmtpd_instance $qpsmtpd = qpsmtpd_instance(); - $SIG{__WARN__} = sub { $qpsmtpd->warn_handler(@_) }; if ($detach) { open STDIN, '/dev/null' or die "/dev/null: $!"; diff --git a/t/qpsmtpd.t b/t/qpsmtpd.t index b2e0ba1..308f821 100644 --- a/t/qpsmtpd.t +++ b/t/qpsmtpd.t @@ -45,8 +45,6 @@ __load_logging(); __config_dir(); __config(); -__warn_level(); - done_testing(); sub __run_hooks { @@ -344,30 +342,6 @@ sub __config { $qp->unfake_hook($_) for qw( config user_config ); } -sub __warn_level { - my ( $level, $msg ) = $qp->warn_level('qwerty'); - is( log_level($level), 'LOGWARN', 'Correct log level with no prefix' ); - is( $msg, 'qwerty', 'Correct message with no prefix' ); - - my $s = 'abc123'; - $s =~ /(abc)/; - ( $level, $msg ) = $qp->warn_level('dvorak'); - is( log_level($level), 'LOGWARN', 'Correct level after $1 assignment' ); - is( $msg, 'dvorak', 'Correct message with no prefix after $1 assignment' ); - - ( $level, $msg ) = $qp->warn_level('NOTICE: asdf'); - is( log_level($level), 'LOGNOTICE', 'Correct level with NOTICE prefix' ); - is( $msg, 'asdf', 'Correct message with NOTICE prefix' ); - - ( $level, $msg ) = $qp->warn_level('EMERGENCY:foo'); - is( log_level($level), 'LOGEMERG', 'Correct level with EMERGENCY prefix' ); - is( $msg, 'foo', 'Correct message with EMERGENCY prefix' ); - - ( $level, $msg ) = $qp->warn_level('NOTICE != LOGNOTICE'); - is( log_level($level), 'LOGWARN', 'Correct level with no colon' ); - is( $msg, 'NOTICE != LOGNOTICE', 'Correct message with no colon' ); -} - 1; package FakeAddress;