1Log::Dispatch::ConfigurUasteorr:C:oAnntyr(i3b)uted PerlLDoogc:u:mDeinstpaatticohn::Configurator::Any(3)
2
3
4

NAME

6       Log::Dispatch::Configurator::Any - Configurator implementation with
7       Config::Any
8

VERSION

10       version 1.122640
11

PURPOSE

13       Use this module in combination with Log::Dispatch::Config to allow many
14       formats of configuration file to be loaded, via the Config::Any module.
15

SYNOPSIS

17       In the traditional Log::Dispatch::Config way:
18
19        use Log::Dispatch::Config; # loads Log::Dispatch
20        use Log::Dispatch::Configurator::Any;
21
22        my $config = Log::Dispatch::Configurator::Any->new('log.yml');
23        Log::Dispatch::Config->configure($config);
24
25        # nearby piece of code
26        my $log = Log::Dispatch::Config->instance;
27        $log->alert('Hello, world!');
28
29       Alternatively, without a config file on disk:
30
31        use Log::Dispatch::Config; # loads Log::Dispatch
32        use Log::Dispatch::Configurator::Any;
33
34        my $confhash = {
35            dispatchers => ['screen]',
36            screen = {
37                class => 'Log::Dispatch::Screen',
38                min_level => 'debug',
39            },
40        };
41
42        my $config = Log::Dispatch::Configurator::Any->new($confhash);
43        Log::Dispatch::Config->configure($config);
44
45        # nearby piece of code
46        my $log = Log::Dispatch::Config->instance;
47        $log->alert('Hello, world!');
48

DESCRIPTION

50       Log::Dispatch::Config is a wrapper for Log::Dispatch and provides a way
51       to configure Log::Dispatch objects with configuration files. Somewhat
52       like a lite version of log4j and Log::Log4perl it allows multiple log
53       destinations. The standard configuration file format for
54       Log::Dispatch::Config is AppConfig.
55
56       This module plugs in to Log::Dispatch::Config and allows the use of
57       other file formats, in fact any format supported by the Config::Any
58       module. As a bonus you can also pass in a configuration data structure
59       instead of a file name.
60

USAGE

62       Follow the examples in the "SYNOPSIS". If you are using an external
63       configuration file, be aware that you are required to use a filename
64       extension (e.g.  ".yml" for YAML).
65
66       Below are a couple of tips and tricks you may find useful.
67
68   Fall-back default config
69       Being able to use a configuration data structre instead of a file on
70       disk is handy when you want to provide application defaults which the
71       user then replaces with their own settings. For example you could have
72       the following:
73
74        my $defaults = {
75            dispatchers => ['screen'],
76            screen => {
77                class     => 'Log::Dispatch::Screen',
78                min_level => 'debug',
79            },
80        };
81
82        my $config_file = '/etc/myapp_logging.conf';
83        my $config = $ENV{MYAPP_LOGGING_CONFIG} || $ARGV[0] ||
84            ( -e $config_file ? $config_file : $defaults);
85
86        Log::Dispatch::Config->configure_and_watch(
87            Log::Dispatch::Configurator::Any->new($config) );
88        my $dispatcher = Log::Dispatch::Config->instance;
89
90       With the above code, your application will check for a filename in an
91       environment variable, then a filename as a command line argument, then
92       check for a file on disk, and finally use its built-in defaults.
93
94   Dealing with a "dispatchers" list
95       Log::Dispatch::Config requires that a global setting "dispatchers" have
96       a list value (i.e. your list of dispatchers). A few config file formats
97       do not support list values at all, or list values at the global level
98       (two examples being Config::Tiny and Config::General).
99
100       This module allows you to have a small grace when there is only one
101       dispatcher in use. Write the configuration file normally, and the
102       single-item "dispatchers" value will automatically be promoted to a
103       list. In other words:
104
105        # myapp.ini
106        dispatchers = screen
107
108        # this becomes a config of:
109        $config = { dispatchers => 'screen', ... };
110
111        # so this module promotes it to:
112        $config = { dispatchers => ['screen'], ... };
113
114       If you want more than one dispatcher, you then need to use a config
115       file format which supports these lists natively, I'm afraid. A good
116       suggestion might be YAML.
117

THANKS

119       My thanks to "miyagawa" for writing Log::Dispatch::Config, from where I
120       also took some tests. Also thanks to Florian Merges for his YAML
121       Configurator, which was a useful example and saved me much time.
122

AUTHOR

124       Oliver Gorwits <oliver@cpan.org>
125
127       This software is copyright (c) 2012 by University of Oxford.
128
129       This is free software; you can redistribute it and/or modify it under
130       the same terms as the Perl 5 programming language system itself.
131
132
133
134perl v5.28.0                      2012-09-20Log::Dispatch::Configurator::Any(3)
Impressum