null logger
This commit is contained in:
parent
0cb5749afc
commit
bcbaf5e75d
6 changed files with 42 additions and 13 deletions
1
Changes
1
Changes
|
@ -1,6 +1,7 @@
|
||||||
Revision history for Perl extension Log-Mini
|
Revision history for Perl extension Log-Mini
|
||||||
|
|
||||||
{{$NEXT}}
|
{{$NEXT}}
|
||||||
|
- Null logger
|
||||||
|
|
||||||
0.1.1 2019-03-19T20:44:04Z
|
0.1.1 2019-03-19T20:44:04Z
|
||||||
- Error in the constructor was fixed. 0.1.0 removed from CPAN.
|
- Error in the constructor was fixed. 0.1.0 removed from CPAN.
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
"web" : "https://github.com/alpha6/Log-Mini"
|
"web" : "https://github.com/alpha6/Log-Mini"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version" : "0.1.1",
|
"version" : "0.2.0",
|
||||||
"x_serialization_backend" : "JSON::PP version 2.93",
|
"x_serialization_backend" : "JSON::PP version 2.93",
|
||||||
"x_static_install" : 1
|
"x_static_install" : 1
|
||||||
}
|
}
|
||||||
|
|
12
README.md
12
README.md
|
@ -6,17 +6,17 @@ Log::Mini - It's a very simple logger which can log your messages to a file or S
|
||||||
|
|
||||||
use Log::Mini;
|
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');
|
$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');
|
$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');
|
$file_logger->info('message to log file');
|
||||||
|
|
||||||
#prevent buffered output. May slow down your application!
|
#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
|
#format message with sprintf
|
||||||
$logger->info('Message with %s %s', 'some', 'additional info');
|
$logger->info('Message with %s %s', 'some', 'additional info');
|
||||||
|
@ -24,6 +24,10 @@ Log::Mini - It's a very simple logger which can log your messages to a file or S
|
||||||
#log method for better compatibility
|
#log method for better compatibility
|
||||||
$logger->log('info', 'information message');
|
$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
|
# DESCRIPTION
|
||||||
|
|
||||||
Log::Mini is a very simple logger which can log your messages to a file or STDERR.
|
Log::Mini is a very simple logger which can log your messages to a file or STDERR.
|
||||||
|
|
|
@ -3,12 +3,8 @@ package Log::Mini;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
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/;
|
use feature qw/say/;
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,9 +15,15 @@ sub new {
|
||||||
$type = 'stderr' unless defined $type;
|
$type = 'stderr' unless defined $type;
|
||||||
|
|
||||||
if ( $type eq 'file' ) {
|
if ( $type eq 'file' ) {
|
||||||
|
require Log::Mini::LoggerFILE;
|
||||||
return Log::Mini::LoggerFILE->new(@_);
|
return Log::Mini::LoggerFILE->new(@_);
|
||||||
}
|
}
|
||||||
|
elsif ( $type eq 'null' ) {
|
||||||
|
require Log::Mini::LoggerNULL;
|
||||||
|
return Log::Mini::LoggerNULL->new(@_);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
require Log::Mini::LoggerSTDERR;
|
||||||
return Log::Mini::LoggerSTDERR->new(@args);
|
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;
|
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');
|
$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');
|
$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');
|
$file_logger->info('message to log file');
|
||||||
|
|
||||||
#prevent buffered output. May slow down your application!
|
#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
|
#log method for better compatibility
|
||||||
$logger->log('info', 'information message');
|
$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
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
|
12
lib/Log/Mini/LoggerNULL.pm
Normal file
12
lib/Log/Mini/LoggerNULL.pm
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package Log::Mini::LoggerNULL;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'Log::Mini::LoggerBase';
|
||||||
|
|
||||||
|
sub _print {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -13,6 +13,12 @@ subtest 'creates stderr logger' => sub {
|
||||||
isa_ok $logger, 'Log::Mini::LoggerSTDERR';
|
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 {
|
subtest 'creates file logger' => sub {
|
||||||
my $file = File::Temp->new;
|
my $file = File::Temp->new;
|
||||||
my $logger = Log::Mini->new('file' => $file->filename);
|
my $logger = Log::Mini->new('file' => $file->filename);
|
||||||
|
|
Loading…
Reference in a new issue