Tatsuhiko Miyagawa


Plack::Middleware::Log::Contextual - integrate Log::Contextual with Plack/PSGI logger middleware


  # in your PSGI web application
  use Log::Contextual qw(:log);

  log_info  { "Information" };
  log_fatal { "ZOMG this shouldn't happen: " . $self->dump_stuff };

  # standalone mode
  use Plack::Builder;
  use Log::Dispatchouli;

  my $ld = Log::Dispatchouli->new(...);

  builder {
      enable "Log::Contextual", logger => $ld;

  # PSGI logger mode
  use Plack::Builder;

  builder {
      enable "ConsoleLogger"; # should come before Log::Contextual
      enable "Log::Contextual";


Plack::Middleware::Log::Contextual is a PSGI middleware component that integrates Log::Contextual with your application. It works as a standalone and could also be used in combination with PSGI logger framework.


Standalone mode

You can use Log::Contextual as a standalone, meaning you can configure the logger object by yourself in the PSGI setup, and all the logging calls get propagated to the logger object you configured.

  use Plack::Builder;
  use Log::Log4perl qw(:easy);

  my $logger = Log::Log4perl->get_logger;

  builder {
      enable "Log::Contextual", logger => $logger;

PSGI logger mode

This middleware also works with the middleware components that support psgix.logger extention, such as Plack::Middleware::SimpleLogger, Plack::Middleware::LogDispatch or Plack::Middleware::ConsoleLogger.

  use Plack::Builder;

  builder {
      enable "ConsoleLogger";
      enable "Log::Contextual", level => "debug";

Note that the PSGI logger should be applied before this middleware.

Unlike the standalone mode where you configure the minimum (and maximum) level in the logger, you should configure the minimum level in the middleware configuration like seen above. It defaults to debug.


Tatsuhiko Miyagawa <miyagawa@bulknews.net>


Copyright 2011- Tatsuhiko Miyagawa


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Hosting generously
sponsored by Bytemark