[dancer-users] Dancer2::Plugin::LogReport - basic setup

Andrew Beverley andy at andybev.com
Wed Jan 4 08:12:59 GMT 2017


On Wed, 4 Jan 2017 Nathan Bailey wrote:

>  I'm endeavouring to use Dancer2::Plugin::LogReport so that all our
> errors go to one log file.
> 
> As I understand the documentation (POD in
> Dancer2::Plugin::LogReport), I need to:
> 1. Add logging information to my yml

Yes, although if you just want to test it initially, then you don't
need any config and any messages will go to STDERR (I think).

To send Dancer internal logs to Log::Report, you just need

  logger: "LogReport"

in your config.

To add a dispatcher to send the messages elsewhere, you also need

  engines:
    logger:
      LogReport:
      ...

As per the docs.

> 2. Add use Log::Report ();

This is no longer needed (sorry, I thought the docs had been updated).

> and use Dancer2::Plugin::LogReport mode =>
> DEBUG; to my main route handler module
> 3. use Log::Report; in my modules

Correct.

> Presumably, however, I need to tell the modules about my Log::Report
> configuration. Does this mean I need a:
> dispatcher 'FILE', 'log', mode => 'DEBUG', to =>
> '/path/mylogfile.log';
> 
> in every method/subroutine?

No, all you need in your modules is:

  use Log::Report;

> I assume not, but I can't see how the non-Dancer2 modules are getting
> the config information since they are ignorant of the .yml file.

Log::Report maintains some global space that all messages go to. When a
message is logged (regardless of where it is logged from) that will
trigger the logging code in the Dancer plugin. The Dancer plugin knows
your config, so it all Just Works.

Are you having problems which means that is not happening?

Andy


More information about the dancer-users mailing list