Skip to content

[challenge] caller depth #99

Open
Open
@XSven

Description

@XSven

I have created an Exception class that consumes the Throwable Moo role. The Exception class is the base class of further classes like for example XML::Exception. This is an excerpt from the Exception class

has _logger => ( is => 'lazy', isa => InstanceOf[ 'Log::Any::Proxy' ], init_arg => undef );

sub BUILD {
  my ( $self ) = @_;
  $self->_logger->errorf( $self->message ) if $self->has_message;
  return;
}

sub _build__logger {
  my ( $self ) = @_;
  return Log::Any->get_logger( category => blessed( $self ) );
}

As you can see errorf() is called in the BUILD() method.

What I want is to log at the place where the exception is raised.

If my consumer is Log::Log4perl, I have to do some wrapper registration

Log::Log4perl->wrapper_register( 'XML::Exception' );
Log::Log4perl->wrapper_register( 'Exception' );
Log::Log4perl->wrapper_register( 'Throwable' );

I dislike that although I cannot clearly state why. First it works only for Log::Log4perl. Second who is responsible for the adjustment of the "caller depth"? Is it the producer or the consumer? Do we need an amendment of the Log::Any::Adapter interface so that "caller depth" information can be passed to any adapter whether he needs it or not?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions