Permalink
Browse files

Merge branch 'release/1.3095'

  • Loading branch information...
2 parents cb79974 + dc79c9d commit 5dc85b02544bce5a3f765fc354e61884ec798872 @xsawyerx xsawyerx committed Apr 1, 2012
View
10 CHANGES
@@ -1,5 +1,15 @@
{{$NEXT}}
+1.3095 01.04.2012
+
+ [ BUG FIXES ]
+ * Small fix to skip tests when YAML is not available.
+ (Sawyer X)
+
+ [ ENHANCEMENTS ]
+ * Added 'info' log level for messages that should always go to the logs
+ but aren't really debug, warning or error messages (Ovid)
+
1.3094 31.03.2012
[ BUG FIXES ]
View
12 lib/Dancer.pm
@@ -5,7 +5,7 @@ use warnings;
use Carp;
use Cwd 'realpath';
-our $VERSION = '1.3094';
+our $VERSION = '1.3095';
our $AUTHORITY = 'SUKRIA';
use Dancer::App;
@@ -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
2 lib/Dancer/Config.pm
@@ -491,6 +491,8 @@ B<core>, B<debug>, B<warning> or B<error>.
=item B<debug> : all messages are logged
+=item B<info> : only info, warning and error messages are logged
+
=item B<warning> : only warning and error messages are logged
=item B<error> : only error messages are logged
View
15 lib/Dancer/Cookbook.pod
@@ -770,11 +770,12 @@ To enable logging to a file, add the following to your config.yml:
Then you can choose which kind of messages you want to actually log:
- log: 'core' # will log debug, warning and errors, and messages from
+ log: 'core' # will log all messages, including messages from
# Dancer itself
- log: 'debug' # will log debug, warning and errors
- log: 'warning' # will log warning and errors
- log: 'error' # will log only errors
+ log: 'debug' # will log debug, info, warning and error messages
+ log: 'info' # will log info, warning and error messages
+ log: 'warning' # will log warning and error messages
+ log: 'error' # will log error messages
If you're using the C<file> logging engine, a directory C<appdir/logs> will be
created and will host one logfile per environment. The log message contains the
@@ -783,13 +784,11 @@ information (file and line).
=head3 Logging your own messages
-Just call L<debug|Dancer/debug>, L<warning|Dancer/warning> or
-L<error|Dancer/error> with your message:
+Just call L<debug|Dancer/debug>, L<warning|Dancer/warning>,
+L<error|Dancer/error> or L<info|Dancer/info> with your message:
debug "This is a debug message from my app.";
-
-
=head1 RESTING
=head2 Writing a REST application
View
11 lib/Dancer/Introduction.pod
@@ -398,19 +398,20 @@ start the logger engine in your config.yml
Then you can choose which kind of messages you want to actually log:
- log: 'debug' # will log debug, warning and errors
- log: 'warning' # will log warning and errors
- log: 'error' # will log only errors
+ log: 'debug' # will log debug, warning, error and info messages
+ log: 'info' # will log info, warning and error messages
+ log: 'warning' # will log warning and error messages
+ log: 'error' # will log error messages
A directory appdir/logs will be created and will host one logfile per
environment. The log message contains the time it was written, the PID of the
current process, the message and the caller information (file and line).
-To log messages, use the debug, warning and error methods, for instance:
+To log messages, use the debug, info, warning and error functions. For
+instance:
debug "This is a debug message";
-
=head1 USING TEMPLATES
=head1 VIEWS
View
1 lib/Dancer/Logger.pm
@@ -33,6 +33,7 @@ sub _serialize {
sub core { defined($logger) and $logger->core( _serialize(@_) ) }
sub debug { defined($logger) and $logger->debug( _serialize(@_) ) }
+sub info { defined($logger) and $logger->info( _serialize(@_) ) }
sub warning { defined($logger) and $logger->warning( _serialize(@_) ) }
sub error { defined($logger) and $logger->error( _serialize(@_) ) }
View
14 lib/Dancer/Logger/Abstract.pm
@@ -23,9 +23,10 @@ my $levels = {
# levels > 0 are for end-users only
debug => 1,
- warn => 2,
- warning => 2,
- error => 3,
+ info => 2,
+ warn => 3,
+ warning => 3,
+ error => 4,
};
my $log_formats = {
@@ -132,6 +133,7 @@ sub format_message {
sub core { $_[0]->_should('core') and $_[0]->_log('core', $_[1]) }
sub debug { $_[0]->_should('debug') and $_[0]->_log('debug', $_[1]) }
+sub info { $_[0]->_should('info') and $_[0]->_log('info', $_[1]) }
sub warning { $_[0]->_should('warning') and $_[0]->_log('warning', $_[1]) }
sub error { $_[0]->_should('error') and $_[0]->_log('error', $_[1]) }
@@ -252,14 +254,18 @@ 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
application to die.
=head2 _should
-Checks a certain level number against a certain level type (core, debug,
+Checks a certain level number against a certain level type (core, debug, info
warning, error).
=head1 AUTHOR
View
4 script/dancer
@@ -933,9 +933,9 @@ template: \"simple\"
# file: log message to a file in log/
logger: \"console\"
-# the log level for this environement
+# the log level for this environment
# core is the lowest, it shows Dancer's core log messages as well as yours
-# (debug, warning and error)
+# (debug, info, warning and error)
log: \"core\"
# should Dancer consider warnings as critical errors?
View
4 t/01_config/08_environments.t
@@ -1,6 +1,10 @@
use strict;
use warnings;
use Test::More import => ['!pass'];
+use Dancer::ModuleLoader;
+
+Dancer::ModuleLoader->load('YAML')
+ or plan skip_all => 'YAML is needed to run this test';
plan tests => 5;
View
58 t/11_logger/01_abstract.t
@@ -1,55 +1,29 @@
-use Test::More tests => 20, import => ['!pass'];
+use Test::More tests => 28, import => ['!pass'];
use strict;
use warnings;
use Dancer;
+use Dancer::Logger::Abstract;
-use t::lib::EasyMocker;
-
-use_ok 'Dancer::Logger::Abstract';
-
-my $l = Dancer::Logger::Abstract->new;
+my @log_levels = qw(core debug info warning error);
+my $l = Dancer::Logger::Abstract->new;
isa_ok $l, 'Dancer::Logger::Abstract';
-can_ok $l, (qw(_log _should debug warning error));
+can_ok $l, (qw(_log _should), @log_levels);
eval { $l->_log };
like $@, qr/_log not implemented/, "_log is a virtual method";
-# core log level
-set log => 'core';
-for my $levels (qw{core debug warning error}) {
- eval { $l->$levels("foo") };
- like $@ => qr/not implemented/;
-}
-
-# debug log level
-set log => 'debug';
-for my $levels (qw{debug warning error}) {
- eval { $l->$levels("foo") };
- like $@ => qr/not implemented/;
-}
-for my $levels (qw{core}) {
- is ($l->$levels("foo"), "");
-}
+my @implemented;
-# warning log level
-set log => 'warning';
-for my $levels (qw{warning error}) {
- eval { $l->$levels("foo") };
- like $@ => qr/not implemented/;
+for my $level (0 .. $#log_levels) {
+ set log => $log_levels[0];
+ for my $levels (@log_levels) {
+ eval { $l->$levels("foo") };
+ like $@ => qr/not implemented/;
+ }
+ for my $levels (@implemented) {
+ is($l->$levels("foo"), "");
+ }
+ push @implemented => shift @log_levels;
}
-for my $levels (qw{core debug}) {
- is ($l->$levels("foo"), "");
-}
-
-# error log level
-set log => 'error';
-for my $levels (qw{error}) {
- eval { $l->$levels("foo") };
- like $@ => qr/not implemented/;
-}
-for my $levels (qw{core debug warning}) {
- is ($l->$levels("foo"), "");
-}
-
View
16 t/11_logger/03_file.t
@@ -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
6 t/11_logger/04_console.t
@@ -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
2 t/11_logger/06_null.t
@@ -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
2 t/11_logger/07_diag.t
@@ -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
2 t/11_logger/10_note.t
@@ -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 5dc85b0

Please sign in to comment.