Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This seems as if it should be simple, but I've been searching everywhere and can't find an answer.

I inherited a script that used MooseX::Log::Dispatch. It had a setup section that looked like:

has log_dispatch_conf => ( is => 'ro', isa => 'HashRef', lazy => 1, required => 1, default => sub { return { class => 'Log::Dispatch::File', min_level => 'debug', filename => $self->config->{mail_log_file}, mode => '>>', newline => 1, format => '[%d] [%p] %m at %F line %L%n', }; }, );
I need to do some additional things with this, and no one seems to use this module, so I switched to doing it manually:
has 'logger' => ( is => 'ro', isa => 'Log::Dispatch', required => 1, lazy => 1, default => sub { return Log::Dispatch->new( outputs => [ [ 'File', min_level => 'debug', filename => $self->config->{mail_log_file}, mode => '>>', newline => 1, format => '[%d] [%p] %m at %F line %L%n', ], # ....
Unfortunately, it seems that Log::Dispatch itself doesn't use the format attribute. And I can't figure out how to apply this. I see there's a configurator module, but I don't want to create an entire configuration file, I just want to get this format into the output. Searching for things like "perl Log Dispatch format" isn't helping. How do I accomplish this?

Replies are listed 'Best First'.
Re: Format strings with Log::Dispatch?
by 1nickt (Canon) on Nov 12, 2019 at 17:52 UTC

    Hi, Log::Dispatch is just a dispatcher and the logging objects to which it dispatches messages are what determine the output. You can use an existing one, (including possibly of interest Log::Dispatch::Code to output to a coderef of your own devising), write your own output class, or use Log::Dispatch::Config in place of the parent class.

    Also see the doc for configuration in the Role you are currently using.

    Hope this helps!


    The way forward always starts with a minimal test.