Log::D...r::Any(3pm)
π Log::Dispatch::Configurator::Any π
okay bestie so this is Log::Dispatch::Configurator::Any, a lil piece of the User Contributed Perl Documentation collection, and honestly? it's giving "small module, huge main character energy." let's get into it π«Ά
β¨ VERSION β¨
version 1.122640 β yeah it's been around a minute, it's vintage, it's iconic π
π― PURPOSE π―
use this module with Log::Dispatch::Config when you want to load your config files in so many different formats β like, whatever format, it does not care β because it hands all of that off to Config::Any. that's the whole job. that's the vibe. π
πΈ SYNOPSIS πΈ
the classic way, the traditional Log::Dispatch::Config way:
use Log::Dispatch::Config; # loads Log::Dispatch
use Log::Dispatch::Configurator::Any;
my $config = Log::Dispatch::Configurator::Any->new('log.yml');
Log::Dispatch::Config->configure($config);
# nearby piece of code
my $log = Log::Dispatch::Config->instance;
$log->alert('Hello, world!');
or, if you're feeling spicy and you literally do not have a config file on disk, you can just vibe with a hash instead:
use Log::Dispatch::Config; # loads Log::Dispatch
use Log::Dispatch::Configurator::Any;
my $confhash = {
dispatchers => ['screen]',
screen = {
class => 'Log::Dispatch::Screen',
min_level => 'debug',
},
};
my $config = Log::Dispatch::Configurator::Any->new($confhash);
Log::Dispatch::Config->configure($config);
# nearby piece of code
my $log = Log::Dispatch::Config->instance;
$log->alert('Hello, world!');
(and yes, copy that code block character for character, bestie. it is what it is. π)
π DESCRIPTION π
so Log::Dispatch::Config is a wrapper around Log::Dispatch, and it lets you set up your Log::Dispatch objects using config files. it's kinda like a lite version of log4j and Log::Log4perl β it lets you have multiple log destinations, which is a whole slay. the standard config file format for Log::Dispatch::Config is AppConfig.
but here's where this module comes in: it plugs into Log::Dispatch::Config and unlocks other file formats β literally any format that Config::Any supports. and as a lil bonus? you can also just pass in a configuration data structure instead of a filename. no file required. β¨
π οΈ USAGE π οΈ
just follow the examples up in the SYNOPSIS, bestie. but heads up: if you're using an external configuration file, you are required to use a filename extension (like .yml for YAML). no extension = no vibe check passed. π
below are a couple of tips and tricks you might find useful π
π Fall-back default config
being able to pass a configuration data structure instead of a file on disk is so handy when you want to ship application defaults that the user can then replace with their own settings. like, for example, you could have this:
my $defaults = {
dispatchers => ['screen'],
screen => {
class => 'Log::Dispatch::Screen',
min_level => 'debug',
},
};
my $config_file = '/etc/myapp_logging.conf';
my $config = $ENV{MYAPP_LOGGING_CONFIG} || $ARGV[0] ||
( -e $config_file ? $config_file : $defaults);
Log::Dispatch::Config->configure_and_watch(
Log::Dispatch::Configurator::Any->new($config) );
my $dispatcher = Log::Dispatch::Config->instance;
with that code, your app checks for a filename in an environment variable, then a filename as a command line argument, then it checks for a file on disk, and finally it falls back to its built-in defaults. the pipeline is pipeline-ing. π
π¦ Dealing with a "dispatchers" list
Log::Dispatch::Config requires that the global setting dispatchers has a list value (i.e. your list of dispatchers, obvi). but a few config file formats do not support list values at all, or they don't support list values at the global level β two examples being Config::Tiny and Config::General. annoying, right?
so this module gives you a lil grace when you've only got one dispatcher in use. write the config file like normal, and the single-item dispatchers value gets automatically promoted to a list. in other words:
# myapp.ini
dispatchers = screen
# this becomes a config of:
$config = { dispatchers => 'screen', ... };
# so this module promotes it to:
$config = { dispatchers => ['screen'], ... };
but if you want more than one dispatcher, you're gonna need a config file format that supports these lists natively, i'm afraid π a good suggestion might be YAML. (it's always YAML.)
π THANKS π
big thanks to "miyagawa" for writing Log::Dispatch::Config β i also stole some tests from there, no shame, it's a compliment fr fr. and also thanks to Florian Merges for his YAML Configurator, which was a super useful example and saved me soooo much time. π«Άβ¨
π AUTHOR π
Oliver Gorwits <oliver@cpan.org>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2012 by University of Oxford.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π (yes, that means go wild, but read the terms, bestie.)
and that's the whole page!! π this one wasperl v5.34.0flavored, dated2022-06-15, and honestly it ate. no cap. byeeee ππ β¨
π¦ where this page comes from
- debian bookworm: liblog-dispatch-configurator-any-perl 1.122640-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblog-dispatch-configurator-any-perl 1.122640-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblog-dispatch-configurator-any-perl 1.122640-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblog-dispatch-configurator-any-perl 1.122640-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblog-dispatch-configurator-any-perl 1.122640-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms