aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2015-08-05 16:18:01 +0200
committerAngelo Naselli <anaselli@linux.it>2015-08-05 16:18:01 +0200
commita29cbbb563d683caae5dd459715af528c2f3eed0 (patch)
tree04b75c925fe2aa72fa3a6ebd2bcdef1c46b39274
parent1435dd35e9f18527da90edb0de6e639281a7d2b1 (diff)
downloadmanatools-a29cbbb563d683caae5dd459715af528c2f3eed0.tar
manatools-a29cbbb563d683caae5dd459715af528c2f3eed0.tar.gz
manatools-a29cbbb563d683caae5dd459715af528c2f3eed0.tar.bz2
manatools-a29cbbb563d683caae5dd459715af528c2f3eed0.tar.xz
manatools-a29cbbb563d683caae5dd459715af528c2f3eed0.zip
Added setmask to mask logging level
-rw-r--r--lib/ManaTools/Shared/Logging.pm24
-rw-r--r--t/11-Shared-Logging.t28
2 files changed, 45 insertions, 7 deletions
diff --git a/lib/ManaTools/Shared/Logging.pm b/lib/ManaTools/Shared/Logging.pm
index e2f31eb3..46f102c8 100644
--- a/lib/ManaTools/Shared/Logging.pm
+++ b/lib/ManaTools/Shared/Logging.pm
@@ -159,6 +159,7 @@ sub DEMOLISH {
Sys::Syslog::closelog();
}
+
#=============================================================
=head2 R
@@ -321,6 +322,29 @@ sub D {
$self->S('debug', $s, @para);
}
+#=============================================================
+
+=head2 setmask
+
+=head3 INPUT
+
+ $self: this object
+ $mask: new log mask
+
+=head3 DESCRIPTION
+
+ Sets the log mask for the current process to $mask and returns the old mask.
+ See Sys::Syslog::setlogmask for details.
+
+=cut
+
+#=============================================================
+sub setmask {
+ my ($self, $mask) = @_;
+
+ Sys::Syslog::setlogmask($mask);
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
diff --git a/t/11-Shared-Logging.t b/t/11-Shared-Logging.t
index db27d5b2..3840eeea 100644
--- a/t/11-Shared-Logging.t
+++ b/t/11-Shared-Logging.t
@@ -1,6 +1,7 @@
use 5.006;
use strict;
use warnings FATAL => 'all';
+use Sys::Syslog qw(:macros);
use Test::More;
use Data::Dumper;
@@ -18,24 +19,37 @@ ok ( $obj->E("test err %d", 3), 'err_logging');
ok ( $obj->D("test debug %d", 4), 'debug_logging');
$obj = undef;
-my $o = ManaTools::Shared::JournalCtl->new(this_boot=>1,);
-$o->identifier('test_logging');
+# let's test an identified logger
ok ( $obj = ManaTools::Shared::Logging->new(ident => 'test_logging'), 'new_test_logging');
ok ( $obj->D("test debug %d", 5), 'debug_logging as test_logging');
ok ( $obj->I("test info %d", 6), 'info_logging as test_logging');
ok ( $obj->W("test warning %d", 7), 'warning_logging as test_logging');
ok ( $obj->E("test err %d", 8), 'err_logging as test_logging');
-#let's wait journalctl to be updated
+
+# disable debug level
+ok ( $obj->setmask( LOG_UPTO(LOG_INFO) ), 'setmask up to info' );
+ok ( $obj->I("test info (debug disabled) %d", 9), 'info with debug disabled as test_logging');
+isnt ( $obj->D("test debug (debug disabled) %d", 10), 1, 'debug disabled as test_logging');
+
+# let's check logged string int journalctl
+my $o = ManaTools::Shared::JournalCtl->new(this_boot=>1,);
+$o->identifier('test_logging');
+# let's wait journalctl to be updated
sleep 1;
my $c = $o->getLog();
my $str = $c->[-1];
-ok($str =~ "test err 8", 'test err found');
+isnt($str =~ /test debug \(debug disabled\) 10/, 1, 'debug disabled');
+ok($str =~ /test info \(debug disabled\) 9/, 'info with debug disabled');
+
$str = $c->[-2];
-ok($str =~ "test warning 7", 'test warning found');
+ok($str =~ /test err 8/, 'test err found');
$str = $c->[-3];
-ok($str =~ "test info 6", 'test info found');
+ok($str =~ /test warning 7/, 'test warning found');
$str = $c->[-4];
-ok($str =~ "test debug 5", 'test debug found');
+ok($str =~ /test info 6/, 'test info found');
+$str = $c->[-5];
+ok($str =~ /test debug 5/, 'test debug found');
+
done_testing;