Skip to content

Commit

Permalink
basic support for Mojo::Log's format() method
Browse files Browse the repository at this point in the history
  • Loading branch information
garu committed Aug 11, 2014
1 parent ff217e5 commit 38eed8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 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)
Expand Down
20 changes: 16 additions & 4 deletions lib/MojoX/Log/Log4perl.pm
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -339,7 +345,13 @@ Finally, there's the Carp functions that do just what the Carp functions do, but
=head1 ATTRIBUTES
The original C<handle> and C<path> 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<handle> and C<path> 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<format> 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<not> 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<level>
Expand Down

0 comments on commit 38eed8d

Please sign in to comment.