From: BENNING, M. (ext) <mar...@at...> - 2012-10-15 10:37:56
|
Hello Log4perl Developers, I noticed that logcroak (die,confess...) always die()s with a stringified version of what you pass to it. Here's an example: --- #!/usr/bin/env perl package Status; use Moose; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); use Carp; use overload q{""} => sub { $_[0]->as_string }, fallback => 1; has 'logger' => ( is => 'ro', isa => 'Log::Log4perl::Logger', lazy => 1, default => sub { return( Log::Log4perl->get_logger('Status') ); }, ); has code => ( is => 'ro', isa => 'Int', required => 1 ); has message => ( is => 'ro', isa => 'Str', required => 1 ); sub as_string { my ($self) = @_; return ( sprintf( 'Status: %s (%s)', $self->message, $self->code ) ); } sub throw { my $self = shift; croak($self); } sub throw_log4perl { my $self = shift; $self->logger->logcroak($self); } package main; use Data::Dumper; my $s = Status->new( code => 500, message => 'Foobar'); eval { $s->throw }; print Dumper($@); eval { $s->throw_log4perl }; print Dumper($@); --- END --- Output: $VAR1 = bless( { 'message' => 'Foobar', 'code' => 500 }, 'Status' ); 2012/10/15 12:19:41 ESB Error: Foobar (500) at log4perl-test.pl line 50 $VAR1 = 'ESB Error: Foobar (500) at log4perl-test.pl line 50 '; --- Shouldn't logcroak log a stringified version and call croak on the value you passed to it instead of calling croak on the log message? The docs say: "Finally, there's the Carp functions that do just what the Carp functions do, but with logging:" Regards, Markus Benning |