<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Plack::Middleware::LogDispatch;
use strict;
use parent qw(Plack::Middleware);
use Plack::Util::Accessor qw(logger);
use Carp ();

sub prepare_app {
    my $self = shift;
    unless ($self-&gt;logger) {
        Carp::croak "logger is not defined";
    }
}

sub call {
    my($self, $env) = @_;

    $env-&gt;{'psgix.logger'} = sub {
        my $args = shift;
        $args-&gt;{level} = 'critical' if $args-&gt;{level} eq 'fatal';
        $self-&gt;logger-&gt;log(%$args);
    };

    $self-&gt;app-&gt;($env);
}

1;

__END__

=head1 NAME

Plack::Middleware::LogDispatch - Uses Log::Dispatch to configure logger

=head1 SYNOPSIS

  use Log::Dispatch;

  my $logger = Log::Dispatch-&gt;new;
  $logger-&gt;add( Log::Dispatch::File-&gt;new(...) );
  $logger-&gt;add( Log::Dispatch::DesktopNotification-&gt;new(...) );

  builder {
      enable "LogDispatch", logger =&gt; $logger;
      $app;
  }

  # use with Log::Dispatch::Config
  use Log::Dispatch::Config;
  Log::Dispatch::Config-&gt;configure('/path/to/log.conf');

  builder {
      enable "LogDispatch", logger =&gt; Log::Dispatch::Config-&gt;instance;
      ...
  }

=head1 DESCRIPTION

LogDispatch is a Plack::Middleware component that allows you to use
L&lt;Log::Dispatch&gt; to configure logging object.

=head1 CONFIGURATION

=over 4

=item logger

Log::Dispatch object to send logs to. Required.

=back

=head1 AUTHOR

Tatsuhiko Miyagawa

=head1 SEE ALSO

L&lt;Log::Dispatch&gt;

=cut

</pre></body></html>