Plack::...Log4perl(3)

πŸ’– Plack::Middleware::Log4perl πŸ’–

okay bestie, gather round, because this is the one that makes your logs actually make sense 🫢 It's Plack::Middleware::Log4perl, and its whole job is literally this: Uses Log::Log4perl to configure logger. That's the vibe. That's the whole assignment. ✨


🌸 SYNOPSIS 🌸

here's how it looks when you're living your best life:

my $app = sub {
    my $env =  shift;

    $env->{'psgix.logger'}({ level => 'error', message => 'Hi' });

    return [
        '200',
        [ 'Content-Type' => 'text/plain' ],
        [ "Hello World" ],
    ];
};

# Use your own Log4perl configuration
use Log::Log4perl;
Log::Log4perl::init('/path/to/log4perl.conf');

builder {
    # tell the logger to log with 'plack' category
    enable "Log4perl", category => "plack";
    $app;
}

# Configure with Log4perl middleware options
builder {
    enable "Log4perl", category => "plack", conf => '/path/to/log4perl.conf';
    $app;
}

see how chill that is?? no cap, it's giving effortless 🌈


πŸ¦‹ DESCRIPTION πŸ¦‹

so Log4perl is a Plack::Middleware component, and what it does is let you use Log::Log4perl to configure the logging object psgix.logger for a given category. that's it. that's the tea β˜• the middleware handles the logger setup, you just tell it which category you're repping, and it goes from there. main character energy honestly πŸ‘‘


πŸŽ€ CONFIGURATION πŸŽ€

✨ category ✨

the log4perl category you wanna send your logs to. it defaults to '', which means it sends them to the root logger. so if you don't say anything, everybody's logs get funneled to the top. periodt πŸ’…

✨ conf ✨

the configuration file path β€” or a scalar ref holding the config string β€” for Log::Log4perl to automatically configure. so like, either you hand it a path, or you hand it the actual config text wrapped in a ref. both are valid, both are iconic πŸ“


πŸ‘‘ AUTHOR πŸ‘‘

Tatsuhiko Miyagawa

(absolute legend, show some respect 🫑)


⭐ SEE ALSO ⭐

  • Log::Log4perl
  • Plack::Middleware::LogDispatch

go read those too, bestie, they're part of the whole ecosystem and they're lowkey fire πŸ”₯


ngl, if your logging is a mess and you're out here with <print STDERR> everywhere, this middleware is your sign to level up. iykyk πŸ’€

okay and before you go β€” this whole page is from perl v5.42.3, dated 2026-10-18, filed under Plack::...Log4perl(3). so that's the version, that's the date, and that's your page number πŸŽ€ slay, go log something beautiful πŸ’–βœ¨

πŸ“¦ where this page comes from