On Mon, 15 Oct 2012, BENNING, Markus (ext) wrote: > 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?
I guess that makes sense if you're using it for throwing exceptions, but I've never used it that way and that's the reason why logcroak() (and its companions) is using Log::Log4perl::Logger::warning_render() to format the message before it passes it to croak() et al. Of course, that's not easy to change now, because some people rely on the feature, but as a horrible hack, you could use something like { no warnings qw( redefine ); *Log::Log4perl::Logger::warning_render = sub { return $_[1]; } } We should probably provide a flag you can set. What do you think? > The docs say: "Finally, there's the Carp functions that do just what > the Carp functions do, but with logging:" Fixed! https://github.com/mschilli/log4perl/commit/56c95a2d131678c4908785695fac0e56175c7b44 -- -- Mike Mike Schilli m...@perlmeister.com > 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 > '; > --- > ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct _______________________________________________ log4perl-devel mailing list log4perl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/log4perl-devel