null logger

This commit is contained in:
Denis Fedoseev 2019-04-12 01:01:37 +03:00
parent 0cb5749afc
commit bcbaf5e75d
6 changed files with 42 additions and 13 deletions

View file

@ -1,6 +1,7 @@
Revision history for Perl extension Log-Mini
{{$NEXT}}
- Null logger
0.1.1 2019-03-19T20:44:04Z
- Error in the constructor was fixed. 0.1.0 removed from CPAN.

View file

@ -68,7 +68,7 @@
"web" : "https://github.com/alpha6/Log-Mini"
}
},
"version" : "0.1.1",
"version" : "0.2.0",
"x_serialization_backend" : "JSON::PP version 2.93",
"x_static_install" : 1
}

View file

@ -6,23 +6,27 @@ Log::Mini - It's a very simple logger which can log your messages to a file or S
use Log::Mini;
my $logger = Log::Mini->get_logger(); #STDERR logger used by default. Error is default log level
my $logger = Log::Mini->new(); #STDERR logger used by default. Error is default log level
$logger->error('Error message');
my $debug_logger = Log::Mini->get_logger('stderr', level => 'debug'); #STDERR logger used by default
my $debug_logger = Log::Mini->new('stderr', level => 'debug'); #STDERR logger used by default
$debug_logger->error('Error message');
my $file_logger = Log::Mini->get_logger(file => 'log_file.log');
my $file_logger = Log::Mini->new(file => 'log_file.log');
$file_logger->info('message to log file');
#prevent buffered output. May slow down your application!
my $synced_file_logger = Log::Mini->get_logger(file => 'log_file.log', synced => 1);
my $synced_file_logger = Log::Mini->new(file => 'log_file.log', synced => 1);
#format message with sprintf
$logger->info('Message with %s %s', 'some', 'additional info');
#log method for better compatibility
$logger->log('info', 'information message');
#Null logger - drops all messages to /dev/null
my $logger = Log::Mini->new('null);
$logger->error('Error message'); #Message will be dropped
# DESCRIPTION

View file

@ -3,12 +3,8 @@ package Log::Mini;
use strict;
use warnings;
our $VERSION = "0.1.1";
our $VERSION = "0.2.0";
use Log::Mini::LoggerFILE;
use Log::Mini::LoggerSTDERR;
use Data::Dumper;
use feature qw/say/;
@ -19,9 +15,15 @@ sub new {
$type = 'stderr' unless defined $type;
if ( $type eq 'file' ) {
require Log::Mini::LoggerFILE;
return Log::Mini::LoggerFILE->new(@_);
}
elsif ( $type eq 'null' ) {
require Log::Mini::LoggerNULL;
return Log::Mini::LoggerNULL->new(@_);
}
else {
require Log::Mini::LoggerSTDERR;
return Log::Mini::LoggerSTDERR->new(@args);
}
}
@ -42,13 +44,13 @@ Log::Mini - It's a very simple logger which can log your messages to a file or S
use Log::Mini;
my $logger = Log::Mini->get_logger(); #STDERR logger used by default. Error is default log level
my $logger = Log::Mini->new(); #STDERR logger used by default. Error is default log level
$logger->error('Error message');
my $debug_logger = Log::Mini->get_logger('stderr', level => 'debug'); #STDERR logger used by default
my $debug_logger = Log::Mini->new('stderr', level => 'debug'); #STDERR logger used by default
$debug_logger->error('Error message');
my $file_logger = Log::Mini->get_logger(file => 'log_file.log');
my $file_logger = Log::Mini->new(file => 'log_file.log');
$file_logger->info('message to log file');
#prevent buffered output. May slow down your application!
@ -60,6 +62,10 @@ Log::Mini - It's a very simple logger which can log your messages to a file or S
#log method for better compatibility
$logger->log('info', 'information message');
#Null logger - drops all messages to /dev/null
my $logger = Log::Mini->new('null);
$logger->error('Error message'); #Message will be dropped
=head1 DESCRIPTION

View file

@ -0,0 +1,12 @@
package Log::Mini::LoggerNULL;
use strict;
use warnings;
use base 'Log::Mini::LoggerBase';
sub _print {
return;
}
1;

View file

@ -13,6 +13,12 @@ subtest 'creates stderr logger' => sub {
isa_ok $logger, 'Log::Mini::LoggerSTDERR';
};
subtest 'creates null logger' => sub {
my $logger = Log::Mini->new('null');
isa_ok $logger, 'Log::Mini::LoggerNULL';
};
subtest 'creates file logger' => sub {
my $file = File::Temp->new;
my $logger = Log::Mini->new('file' => $file->filename);