Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Format strings with Log::Dispatch?

by Anonymous Monk
on Nov 12, 2019 at 16:58 UTC ( #11108592=perlquestion: print w/replies, xml ) Need Help??

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 (Abbot) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11108592]
Approved by johngg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-05-25 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (146 votes). Check out past polls.

    Notices?