Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[challenge] caller depth #99

Open
XSven opened this issue May 26, 2023 · 0 comments
Open

[challenge] caller depth #99

XSven opened this issue May 26, 2023 · 0 comments

Comments

@XSven
Copy link
Contributor

XSven commented May 26, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant