Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'release/1.3095'

  • Loading branch information...
commit 5dc85b02544bce5a3f765fc354e61884ec798872 2 parents cb79974 + dc79c9d
Sawyer X xsawyerx authored
10 CHANGES
... ... @@ -1,5 +1,15 @@
1 1 {{$NEXT}}
2 2
  3 +1.3095 01.04.2012
  4 +
  5 + [ BUG FIXES ]
  6 + * Small fix to skip tests when YAML is not available.
  7 + (Sawyer X)
  8 +
  9 + [ ENHANCEMENTS ]
  10 + * Added 'info' log level for messages that should always go to the logs
  11 + but aren't really debug, warning or error messages (Ovid)
  12 +
3 13 1.3094 31.03.2012
4 14
5 15 [ BUG FIXES ]
12 lib/Dancer.pm
@@ -5,7 +5,7 @@ use warnings;
5 5 use Carp;
6 6 use Cwd 'realpath';
7 7
8   -our $VERSION = '1.3094';
  8 +our $VERSION = '1.3095';
9 9 our $AUTHORITY = 'SUKRIA';
10 10
11 11 use Dancer::App;
@@ -52,6 +52,7 @@ our @EXPORT = qw(
52 52 debug
53 53 del
54 54 dirname
  55 + info
55 56 error
56 57 engine
57 58 false
@@ -154,6 +155,7 @@ sub halt { Dancer::SharedData->response->halt(@_);
154 155 Dancer::Continuation::Halted->new->throw;
155 156 }
156 157 sub header { goto &headers }
  158 +sub info { goto &Dancer::Logger::info }
157 159 sub push_header { Dancer::SharedData->response->push_header(@_); }
158 160 sub headers { Dancer::SharedData->response->headers(@_); }
159 161 sub hook { Dancer::Hook->new(@_) }
@@ -1070,6 +1072,14 @@ can be a Dancer::Exception, or a string, or whatever was used to C<die>.
1070 1072
1071 1073 =back
1072 1074
  1075 +=head2 info
  1076 +
  1077 +Logs a message of info level:
  1078 +
  1079 + info "This is a info message";
  1080 +
  1081 +See L<Dancer::Logger> for details on how to configure where log messages go.
  1082 +
1073 1083 =head2 layout
1074 1084
1075 1085 This method is deprecated. Use C<set>:
2  lib/Dancer/Config.pm
@@ -491,6 +491,8 @@ B<core>, B<debug>, B<warning> or B<error>.
491 491
492 492 =item B<debug> : all messages are logged
493 493
  494 +=item B<info> : only info, warning and error messages are logged
  495 +
494 496 =item B<warning> : only warning and error messages are logged
495 497
496 498 =item B<error> : only error messages are logged
15 lib/Dancer/Cookbook.pod
Source Rendered
@@ -770,11 +770,12 @@ To enable logging to a file, add the following to your config.yml:
770 770
771 771 Then you can choose which kind of messages you want to actually log:
772 772
773   - log: 'core' # will log debug, warning and errors, and messages from
  773 + log: 'core' # will log all messages, including messages from
774 774 # Dancer itself
775   - log: 'debug' # will log debug, warning and errors
776   - log: 'warning' # will log warning and errors
777   - log: 'error' # will log only errors
  775 + log: 'debug' # will log debug, info, warning and error messages
  776 + log: 'info' # will log info, warning and error messages
  777 + log: 'warning' # will log warning and error messages
  778 + log: 'error' # will log error messages
778 779
779 780 If you're using the C<file> logging engine, a directory C<appdir/logs> will be
780 781 created and will host one logfile per environment. The log message contains the
@@ -783,13 +784,11 @@ information (file and line).
783 784
784 785 =head3 Logging your own messages
785 786
786   -Just call L<debug|Dancer/debug>, L<warning|Dancer/warning> or
787   -L<error|Dancer/error> with your message:
  787 +Just call L<debug|Dancer/debug>, L<warning|Dancer/warning>,
  788 +L<error|Dancer/error> or L<info|Dancer/info> with your message:
788 789
789 790 debug "This is a debug message from my app.";
790 791
791   -
792   -
793 792 =head1 RESTING
794 793
795 794 =head2 Writing a REST application
11 lib/Dancer/Introduction.pod
Source Rendered
@@ -398,19 +398,20 @@ start the logger engine in your config.yml
398 398
399 399 Then you can choose which kind of messages you want to actually log:
400 400
401   - log: 'debug' # will log debug, warning and errors
402   - log: 'warning' # will log warning and errors
403   - log: 'error' # will log only errors
  401 + log: 'debug' # will log debug, warning, error and info messages
  402 + log: 'info' # will log info, warning and error messages
  403 + log: 'warning' # will log warning and error messages
  404 + log: 'error' # will log error messages
404 405
405 406 A directory appdir/logs will be created and will host one logfile per
406 407 environment. The log message contains the time it was written, the PID of the
407 408 current process, the message and the caller information (file and line).
408 409
409   -To log messages, use the debug, warning and error methods, for instance:
  410 +To log messages, use the debug, info, warning and error functions. For
  411 +instance:
410 412
411 413 debug "This is a debug message";
412 414
413   -
414 415 =head1 USING TEMPLATES
415 416
416 417 =head1 VIEWS
1  lib/Dancer/Logger.pm
@@ -33,6 +33,7 @@ sub _serialize {
33 33
34 34 sub core { defined($logger) and $logger->core( _serialize(@_) ) }
35 35 sub debug { defined($logger) and $logger->debug( _serialize(@_) ) }
  36 +sub info { defined($logger) and $logger->info( _serialize(@_) ) }
36 37 sub warning { defined($logger) and $logger->warning( _serialize(@_) ) }
37 38 sub error { defined($logger) and $logger->error( _serialize(@_) ) }
38 39
14 lib/Dancer/Logger/Abstract.pm
@@ -23,9 +23,10 @@ my $levels = {
23 23
24 24 # levels > 0 are for end-users only
25 25 debug => 1,
26   - warn => 2,
27   - warning => 2,
28   - error => 3,
  26 + info => 2,
  27 + warn => 3,
  28 + warning => 3,
  29 + error => 4,
29 30 };
30 31
31 32 my $log_formats = {
@@ -132,6 +133,7 @@ sub format_message {
132 133
133 134 sub core { $_[0]->_should('core') and $_[0]->_log('core', $_[1]) }
134 135 sub debug { $_[0]->_should('debug') and $_[0]->_log('debug', $_[1]) }
  136 +sub info { $_[0]->_should('info') and $_[0]->_log('info', $_[1]) }
135 137 sub warning { $_[0]->_should('warning') and $_[0]->_log('warning', $_[1]) }
136 138 sub error { $_[0]->_should('error') and $_[0]->_log('error', $_[1]) }
137 139
@@ -252,6 +254,10 @@ Logs messages as warning.
252 254
253 255 Logs messages as error.
254 256
  257 +=head2 info
  258 +
  259 +Logs messages as info.
  260 +
255 261 =head2 _log
256 262
257 263 A method to override. If your logger does not provide this, it will cause the
@@ -259,7 +265,7 @@ application to die.
259 265
260 266 =head2 _should
261 267
262   -Checks a certain level number against a certain level type (core, debug,
  268 +Checks a certain level number against a certain level type (core, debug, info
263 269 warning, error).
264 270
265 271 =head1 AUTHOR
4 script/dancer
@@ -933,9 +933,9 @@ template: \"simple\"
933 933 # file: log message to a file in log/
934 934 logger: \"console\"
935 935
936   -# the log level for this environement
  936 +# the log level for this environment
937 937 # core is the lowest, it shows Dancer's core log messages as well as yours
938   -# (debug, warning and error)
  938 +# (debug, info, warning and error)
939 939 log: \"core\"
940 940
941 941 # should Dancer consider warnings as critical errors?
4 t/01_config/08_environments.t
... ... @@ -1,6 +1,10 @@
1 1 use strict;
2 2 use warnings;
3 3 use Test::More import => ['!pass'];
  4 +use Dancer::ModuleLoader;
  5 +
  6 +Dancer::ModuleLoader->load('YAML')
  7 + or plan skip_all => 'YAML is needed to run this test';
4 8
5 9 plan tests => 5;
6 10
58 t/11_logger/01_abstract.t
... ... @@ -1,55 +1,29 @@
1   -use Test::More tests => 20, import => ['!pass'];
  1 +use Test::More tests => 28, import => ['!pass'];
2 2 use strict;
3 3 use warnings;
4 4
5 5 use Dancer;
  6 +use Dancer::Logger::Abstract;
6 7
7   -use t::lib::EasyMocker;
8   -
9   -use_ok 'Dancer::Logger::Abstract';
10   -
11   -my $l = Dancer::Logger::Abstract->new;
  8 +my @log_levels = qw(core debug info warning error);
  9 +my $l = Dancer::Logger::Abstract->new;
12 10 isa_ok $l, 'Dancer::Logger::Abstract';
13   -can_ok $l, (qw(_log _should debug warning error));
  11 +can_ok $l, (qw(_log _should), @log_levels);
14 12
15 13 eval { $l->_log };
16 14 like $@, qr/_log not implemented/, "_log is a virtual method";
17 15
18 16
19   -# core log level
20   -set log => 'core';
21   -for my $levels (qw{core debug warning error}) {
22   - eval { $l->$levels("foo") };
23   - like $@ => qr/not implemented/;
24   -}
25   -
26   -# debug log level
27   -set log => 'debug';
28   -for my $levels (qw{debug warning error}) {
29   - eval { $l->$levels("foo") };
30   - like $@ => qr/not implemented/;
31   -}
32   -for my $levels (qw{core}) {
33   - is ($l->$levels("foo"), "");
34   -}
  17 +my @implemented;
35 18
36   -# warning log level
37   -set log => 'warning';
38   -for my $levels (qw{warning error}) {
39   - eval { $l->$levels("foo") };
40   - like $@ => qr/not implemented/;
  19 +for my $level (0 .. $#log_levels) {
  20 + set log => $log_levels[0];
  21 + for my $levels (@log_levels) {
  22 + eval { $l->$levels("foo") };
  23 + like $@ => qr/not implemented/;
  24 + }
  25 + for my $levels (@implemented) {
  26 + is($l->$levels("foo"), "");
  27 + }
  28 + push @implemented => shift @log_levels;
41 29 }
42   -for my $levels (qw{core debug}) {
43   - is ($l->$levels("foo"), "");
44   -}
45   -
46   -# error log level
47   -set log => 'error';
48   -for my $levels (qw{error}) {
49   - eval { $l->$levels("foo") };
50   - like $@ => qr/not implemented/;
51   -}
52   -for my $levels (qw{core debug warning}) {
53   - is ($l->$levels("foo"), "");
54   -}
55   -
16 t/11_logger/03_file.t
@@ -9,7 +9,7 @@ use Dancer;
9 9 plan skip_all => "File::Temp 0.22 required"
10 10 unless Dancer::ModuleLoader->load( 'File::Temp', '0.22' );
11 11
12   -plan tests => 16;
  12 +plan tests => 18;
13 13
14 14 my $dir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1);
15 15 set appdir => $dir, environment => 'test';
@@ -27,9 +27,10 @@ like $format, qr/\[\d+\] debug @.+> test in/,
27 27 "format looks good";
28 28
29 29 ok($l->_log(debug => "Perl Dancer test message"), "_log works");
30   -ok($l->debug("Perl Dancer test message 2/4"), "debug works");
31   -ok($l->warning("Perl Dancer test message 3/4"), "warning works");
32   -ok($l->error("Perl Dancer test message 4/4"), "error works");
  30 +ok($l->debug("Perl Dancer test message 2/5"), "debug works");
  31 +ok($l->warning("Perl Dancer test message 3/5"), "warning works");
  32 +ok($l->error("Perl Dancer test message 4/5"), "error works");
  33 +ok($l->info("Perl Dancer test message 5/5"), "info works");
33 34
34 35 ok(-f path($dir,'logs','test.log'), "Log file exists");
35 36
@@ -42,9 +43,10 @@ is(Dancer::Logger::File->logdir, $dir2,
42 43 "logdir is ok");
43 44
44 45 ok($l->_log(debug => "Perl Dancer test message with log_path setting"), "_log works");
45   -ok($l->debug("Perl Dancer test message with log_path setting 2/4"), "debug works");
46   -ok($l->warning("Perl Dancer test message with log_path setting 3/4"), "warning works");
47   -ok($l->error("Perl Dancer test message with log_path setting 4/4"), "error works");
  46 +ok($l->debug("Perl Dancer test message with log_path setting 2/5"), "debug works");
  47 +ok($l->warning("Perl Dancer test message with log_path setting 3/5"), "warning works");
  48 +ok($l->error("Perl Dancer test message with log_path setting 4/5"), "error works");
  49 +ok($l->info("Perl Dancer test message with log_path setting 5/5"), "info works");
48 50
49 51 ok(-f path($dir2,'foo.bar'), "Log file foo.bar exists");
50 52
6 t/11_logger/04_console.t
@@ -10,7 +10,7 @@ use Dancer;
10 10 plan skip_all => "Test::Output is needed for this test"
11 11 unless Dancer::ModuleLoader->load('Test::Output');
12 12
13   -plan tests => 7;
  13 +plan tests => 8;
14 14
15 15 use_ok 'Dancer::Logger::Console';
16 16 my $l = Dancer::Logger::Console->new;
@@ -30,3 +30,7 @@ Test::Output::stderr_like( sub { $l->warning("warning message") },
30 30 Test::Output::stderr_like( sub { $l->error("error message") },
31 31 qr/\[\d+\] error @.+> error message in/,
32 32 "error output is sent to STDERR");
  33 +
  34 +Test::Output::stderr_like( sub { $l->info("info message") },
  35 + qr/\[\d+\] info @.+> info message in/,
  36 + "info output is sent to STDERR");
2  t/11_logger/06_null.t
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Null->new;
13 13
14 14 ok defined($l), 'Dancer::Logger::Null object';
15 15 isa_ok $l, 'Dancer::Logger::Null';
16   -can_ok $l, qw(_log debug warning error);
  16 +can_ok $l, qw(_log debug warning error info);
17 17
18 18 my $format = $l->format_message('debug', 'test');
19 19 like $format, qr/\[\d+\] debug @.+> test in/,
2  t/11_logger/07_diag.t
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Diag->new;
13 13
14 14 ok defined($l), 'Dancer::Logger::Diag object';
15 15 isa_ok $l, 'Dancer::Logger::Diag';
16   -can_ok $l, qw(init _log debug warning error);
  16 +can_ok $l, qw(init _log debug warning error info);
17 17
18 18 my $format = $l->format_message('debug', 'test');
19 19 like $format, qr/\[\d+\] debug @.+> test in/,
2  t/11_logger/10_note.t
@@ -13,7 +13,7 @@ my $l = Dancer::Logger::Note->new;
13 13
14 14 ok defined($l), 'Dancer::Logger::Note object';
15 15 isa_ok $l, 'Dancer::Logger::Note';
16   -can_ok $l, qw(init _log debug warning error);
  16 +can_ok $l, qw(init _log debug warning error info);
17 17
18 18 my $format = $l->format_message('debug', 'test');
19 19 like $format, qr/\[\d+\] debug @.+> test in/,

0 comments on commit 5dc85b0

Please sign in to comment.
Something went wrong with that request. Please try again.