MooseX:...Dispatch(3)

πŸ“¦
version 0.02 Β· 2 versions
, in fedora 43

πŸ’– NAME πŸ’–

MooseX::LazyLogDispatch β€” a Logging Role for Moose, bestie. it's giving "your Moose class but with a whole logging glow-up" ✨


🌸 VERSION 🌸

This doc is describing MooseX::LazyLogDispatch version 0.01, okay? oldie but a goodie πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the whole vibe, look:

    package MyApp;
    use Moose;

    with MooseX::LazyLogDispatch;
    # or alternately, use this role instead to give your
    # class the logger methods "debug", "warning", etc...
    # with MooseX::LazyLogDispatch::Levels;

    # This part optional
    #  without it you get some default logging to the screen
    has log_dispatch_conf => (
       is => 'ro',
       isa => 'Log::Dispatch::Configurator',
       lazy => 1,
       required => 1,
       default => sub {
           my $self = shift;
           My::Configurator->new( # <- you write this class!
               file => $self->log_file,
               debug => $self->debug,
           );
       },
    );

    # Here's another variant, using a Log::Dispatch::Configurator-style
    #  hashref to configure things without an explicit subclass
    has log_dispatch_conf => (
       is => 'ro',
       isa => 'HashRef',
       lazy => 1,
       required => 1,
       default => sub {
           my $self = shift;
           return $self->debug
               ? {
                   class     => 'Log::Dispatch::Screen',
                   min_level => 'debug',
                   stderr    => 1,
                   format    => '[%p] %m at %F line %L%n',
               }
               : {
                   class     => 'Log::Dispatch::Syslog',
                   min_level => 'info',
                   facility  => 'daemon',
                   ident     => $self->daemon_name,
                   format    => '[%p] %m',
               };
       },
    );

    sub foo {
        my ($self) = @_;
        $self->logger->debug("started foo");
        ....
        $self->logger->debug('ending foo');
    }

like, that's it. that's the whole thing. slay πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

It's a Log::Dispatch role, and you just... with it into your Moose classes. that's the whole pitch, no cap 🫢


✨ INTERFACE ✨

πŸ“ logger

This method comes free with the role, and it hands you back a Log::Dispatch instance. you can call level-names on it directly β€” exactly like those debug examples up in the synopsis. iykyk πŸ’…

ngl tho, if you want the level-names to just be methods on your own class? use the MooseX::LazyLogDispatch::Levels role instead. main character energy, no middleman 😌

πŸ’œ log_dispatch_config

This is an optional attribute you can give your class, and it's lowkey the whole personality of this module. If you define it as a hashref value, that gets interpreted in the style of the configuration hashrefs documented over in the Log::Dispatch::Config docs β€” y'know, the ones where they show examples of using Log::Dispatch::Configurator for pluggable configuration. 🧚

You can also go full extra and gain greater flexibility by defining your own complete Log::Dispatch::Configurator subclass, and then having your "log_dispatch_config" attribute be an instance of that class. obsessed πŸ’–

By lazy-loading either one (lazy = 1>), you can have the configuration determined at runtime. which is SO nice if you wanna switch up your log format and/or destination at runtime, based on stuff like MooseX::Getopt / MooseX::Daemonize parameters. periodt ✨

And if you just... don't provide this attribute at all? no stress, bestie β€” we'll default to sending everything to the screen in a reasonable debugging format. 🌈

πŸ‘‘ SEE ALSO πŸ‘‘

  • MooseX::LazyLogDispatch::Levels
  • MooseX::LogDispatch
  • Log::Dispatch::Configurator
  • Log::Dispatch::Config
  • Log::Dispatch

🌟 AUTHOR 🌟

Brandon Black "<blblack@gmail.com>" πŸ’«

Based in part on MooseX::LogDispatch by Ash Berlin "<ash@cpan.org>" and "<perigrin@cpan.org>" β€” shoutout to the OGs 🫢


🌈 LICENCE 🌈

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. πŸ’…


and that's a wrap!! this page came to you from the User Contributed Perl Documentation corner of the world, titled MooseX:...Dispatch(3), and it was rendered up all pretty by perl v5.42.0 back on 2025-07-25 πŸŽ€ go forth and log, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from