Permalink
Browse files

Add info log level.

It's set to level 4. Even if errors aren't logged, info will be. I also note a
lot of duplicate tests which can be stripped, but that's another change ...
  • Loading branch information...
1 parent 6c811dd commit 5f01229a5d510710f43fc9d4a882aeedbf47aeb7 Ovid committed with Alexis Sukrieh Mar 27, 2012
View
@@ -52,6 +52,7 @@ our @EXPORT = qw(
debug
del
dirname
+ info
error
engine
false
@@ -154,6 +155,7 @@ sub halt { Dancer::SharedData->response->halt(@_);
Dancer::Continuation::Halted->new->throw;
}
sub header { goto &headers }
+sub info { goto &Dancer::Logger::info }
sub push_header { Dancer::SharedData->response->push_header(@_); }
sub headers { Dancer::SharedData->response->headers(@_); }
sub hook { Dancer::Hook->new(@_) }
@@ -1070,6 +1072,14 @@ can be a Dancer::Exception, or a string, or whatever was used to C<die>.
=back
+=head2 info
+
+Logs a message of info level:
+
+ info "This is a info message";
+
+See L<Dancer::Logger> for details on how to configure where log messages go.
+
=head2 layout
This method is deprecated. Use C<set>:
View
@@ -35,6 +35,7 @@ sub core { defined($logger) and $logger->core( _serialize(@_) ) }
sub debug { defined($logger) and $logger->debug( _serialize(@_) ) }
sub warning { defined($logger) and $logger->warning( _serialize(@_) ) }
sub error { defined($logger) and $logger->error( _serialize(@_) ) }
+sub info { defined($logger) and $logger->info( _serialize(@_) ) }
1;
@@ -26,6 +26,7 @@ my $levels = {
warn => 2,
warning => 2,
error => 3,
+ info => 4,
};
my $log_formats = {
@@ -134,6 +135,7 @@ sub core { $_[0]->_should('core') and $_[0]->_log('core', $_[1]) }
sub debug { $_[0]->_should('debug') and $_[0]->_log('debug', $_[1]) }
sub warning { $_[0]->_should('warning') and $_[0]->_log('warning', $_[1]) }
sub error { $_[0]->_should('error') and $_[0]->_log('error', $_[1]) }
+sub info { $_[0]->_should('info') and $_[0]->_log('info', $_[1]) }
1;
@@ -252,6 +254,10 @@ Logs messages as warning.
Logs messages as error.
+=head2 info
+
+Logs messages as info.
+
=head2 _log
A method to override. If your logger does not provide this, it will cause the
View
@@ -9,7 +9,7 @@ use Dancer;
plan skip_all => "File::Temp 0.22 required"
unless Dancer::ModuleLoader->load( 'File::Temp', '0.22' );
-plan tests => 16;
+plan tests => 18;
my $dir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1);
set appdir => $dir, environment => 'test';
@@ -27,9 +27,10 @@ like $format, qr/\[\d+\] debug @.+> test in/,
"format looks good";
ok($l->_log(debug => "Perl Dancer test message"), "_log works");
-ok($l->debug("Perl Dancer test message 2/4"), "debug works");
-ok($l->warning("Perl Dancer test message 3/4"), "warning works");
-ok($l->error("Perl Dancer test message 4/4"), "error works");
+ok($l->debug("Perl Dancer test message 2/5"), "debug works");
+ok($l->warning("Perl Dancer test message 3/5"), "warning works");
+ok($l->error("Perl Dancer test message 4/5"), "error works");
+ok($l->info("Perl Dancer test message 5/5"), "info works");
ok(-f path($dir,'logs','test.log'), "Log file exists");
@@ -42,9 +43,10 @@ is(Dancer::Logger::File->logdir, $dir2,
"logdir is ok");
ok($l->_log(debug => "Perl Dancer test message with log_path setting"), "_log works");
-ok($l->debug("Perl Dancer test message with log_path setting 2/4"), "debug works");
-ok($l->warning("Perl Dancer test message with log_path setting 3/4"), "warning works");
-ok($l->error("Perl Dancer test message with log_path setting 4/4"), "error works");
+ok($l->debug("Perl Dancer test message with log_path setting 2/5"), "debug works");
+ok($l->warning("Perl Dancer test message with log_path setting 3/5"), "warning works");
+ok($l->error("Perl Dancer test message with log_path setting 4/5"), "error works");
+ok($l->info("Perl Dancer test message with log_path setting 5/5"), "info works");
ok(-f path($dir2,'foo.bar'), "Log file foo.bar exists");
View
@@ -10,7 +10,7 @@ use Dancer;
plan skip_all => "Test::Output is needed for this test"
unless Dancer::ModuleLoader->load('Test::Output');
-plan tests => 7;
+plan tests => 8;
use_ok 'Dancer::Logger::Console';
my $l = Dancer::Logger::Console->new;
@@ -30,3 +30,7 @@ Test::Output::stderr_like( sub { $l->warning("warning message") },
Test::Output::stderr_like( sub { $l->error("error message") },
qr/\[\d+\] error @.+> error message in/,
"error output is sent to STDERR");
+
+Test::Output::stderr_like( sub { $l->info("info message") },
+ qr/\[\d+\] info @.+> info message in/,
+ "info output is sent to STDERR");
View
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Null->new;
ok defined($l), 'Dancer::Logger::Null object';
isa_ok $l, 'Dancer::Logger::Null';
-can_ok $l, qw(_log debug warning error);
+can_ok $l, qw(_log debug warning error info);
my $format = $l->format_message('debug', 'test');
like $format, qr/\[\d+\] debug @.+> test in/,
View
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Diag->new;
ok defined($l), 'Dancer::Logger::Diag object';
isa_ok $l, 'Dancer::Logger::Diag';
-can_ok $l, qw(init _log debug warning error);
+can_ok $l, qw(init _log debug warning error info);
my $format = $l->format_message('debug', 'test');
like $format, qr/\[\d+\] debug @.+> test in/,
View
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Note->new;
ok defined($l), 'Dancer::Logger::Note object';
isa_ok $l, 'Dancer::Logger::Note';
-can_ok $l, qw(init _log debug warning error);
+can_ok $l, qw(init _log debug warning error info);
my $format = $l->format_message('debug', 'test');
like $format, qr/\[\d+\] debug @.+> test in/,

0 comments on commit 5f01229

Please sign in to comment.