From 38eed8d8a8ea715ad4a856ef28724ffa780b868f Mon Sep 17 00:00:00 2001 From: "Breno G. de Oliveira" Date: Mon, 11 Aug 2014 20:19:49 -0300 Subject: [PATCH] basic support for Mojo::Log's format() method --- Changes | 4 ++++ lib/MojoX/Log/Log4perl.pm | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index de06530..bc057cb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for MojoX-Log-Log4perl +0.10 2014-08-11 + - basic support for Mojo::Log's format(), to prevent the + default 404 page from croaking (thanks Sergei Khomutov) + 0.09 2014-03-16 - new history() and max_history_size() to stay up-to-date with Mojolicious's log expectations (thanks Olivier Duclos) diff --git a/lib/MojoX/Log/Log4perl.pm b/lib/MojoX/Log/Log4perl.pm index 76ad6b7..4042ab4 100644 --- a/lib/MojoX/Log/Log4perl.pm +++ b/lib/MojoX/Log/Log4perl.pm @@ -14,17 +14,23 @@ has max_history_size => 10; # to handle log location and formatting. Those make no sense in a Log4perl # environment (where you can set appenders as you wish) so they are # not implemented here. +sub path { warn 'path() is not implemented in MojoX::Log::Log4perl. Please use appenders.' } +sub handle { warn 'handle() is not implemented in MojoX::Log::Log4perl. Please use appenders.' } +sub format { + warn 'format() is not properly implemented in MojoX::Log::Log4perl. Please use appenders.'; + return sub { '[' . localtime(shift) . '] [' . shift() . '] ' . join("\n", @_, '') }; +} sub new { my ($class, $conf_file, $watch) = (@_); - + $conf_file ||= { 'log4perl.rootLogger' => 'DEBUG, SCREEN', 'log4perl.appender.SCREEN' => 'Log::Log4perl::Appender::Screen', 'log4perl.appender.SCREEN.layout' => 'PatternLayout', 'log4perl.appender.SCREEN.layout.ConversionPattern' => '[%d] [mojo] [%p] %m%n', }; - + if ($watch) { Log::Log4perl::init_and_watch($conf_file, $watch); } @@ -92,7 +98,7 @@ sub is_fatal { shift->_get_logger->is_fatal } sub is_level { my ($self, $level) = (@_); return 0 unless $level; - + if ($level =~ m/^(?:trace|debug|info|warn|error|fatal)$/o) { my $is_level = "is_$level"; return $self->_get_logger->$is_level; @@ -339,7 +345,13 @@ Finally, there's the Carp functions that do just what the Carp functions do, but =head1 ATTRIBUTES -The original C and C attributes from C<< Mojo::Log >> are not implemented as they make little sense in a Log4perl environment. The following attributes are still available: +=head2 Differences from Mojo::Log + +The original C and C attributes from C<< Mojo::Log >> are not implemented as they make little sense in a Log4perl environment, and will trigger a warning if you try to use them. + +The C attribute is also not implemented, and will trigger a warning when used. For compatibility with Mojolicious' current I<404> development page, this attribute will work returning a basic formatted message as I<"[ date ] [ level ] message">. We do B recommend you to rely on this as we may remove it in the future. Please use Log4perl's layout formatters instead. + +The following attributes are still available: =head2 C