1Log::Handler::Config(3)User Contributed Perl DocumentatioLnog::Handler::Config(3)
2
3
4

NAME

6       Log::Handler::Config - The main config loader.
7

SYNOPSIS

9           use Log::Handler;
10
11           my $log = Log::Handler->new();
12
13           # Config::General
14           $log->config(config => 'file.conf');
15
16           # Config::Properties
17           $log->config(config => 'file.props');
18
19           # YAML
20           $log->config(config => 'file.yaml');
21
22       Or
23
24           use Log::Handler;
25
26           my $log = Log::Handler->new();
27
28           $log->config(
29               config => 'file.conf'
30               plugin => 'YAML',
31           );
32

DESCRIPTION

34       This module makes it possible to load the configuration from a file.
35       The configuration type is determined by the file extension. It's also
36       possible to mix file extensions with another configuration types.
37

PLUGINS

39           Plugin name             File extensions
40           ------------------------------------------
41           Config::General         cfg, conf
42           Config::Properties      props, jcfg, jconf
43           YAML                    yml, yaml
44
45       If the extension is not defined then "Config::General" is used by
46       default.
47

METHODS

49   config()
50       With this method it's possible to load the configuration for your
51       outputs.
52
53       The following options are valid:
54
55       config
56           With this option you can pass a file name or the configuration as a
57           hash reference.
58
59               $log->config(config => 'file.conf');
60               # or
61               $log->config(config => \%config);
62
63       plugin
64           With this option it's possible to say which plugin you want to use.
65           Maybe you want to use the file extension "conf" with "YAML", which
66           is reserved for the plugin "Config::General".
67
68           Examples:
69
70               # this would use Config::General
71               $log->config(
72                   config => 'file.conf'
73               );
74
75               # this would force .conf with YAML
76               $log->config(
77                   config => 'file.conf',
78                   plugin => 'YAML'
79               );
80
81       section
82           If you want to write the configuration into a global configuration
83           file then you can create a own section for the logger:
84
85               <logger>
86                   <file>
87                       filename = file.log
88                       minlevel = emerg
89                       maxlevel = warning
90                   </file>
91
92                   <screen>
93                       minlevel = emerg
94                       maxlevel = debug
95                   </screen>
96               </logger>
97
98               <another_script_config>
99                   foo = bar
100                   bar = baz
101                   baz = foo
102               </another_script_config>
103
104           Now your configuration is placed in the "logger" section. You can
105           load this section with
106
107               $log->config(
108                   config  => 'file.conf',
109                   section => 'logger',
110               );
111
112               # or if you load the configuration yourself to %config
113
114               $log->config(
115                   config  => \%config,
116                   section => 'logger',
117               );
118
119               # or just
120
121               $log->config( config => $config{logger} );
122

PLUGINS

124           Config::General     -  inspired by the well known apache config format
125           Config::Properties  -  Java-style property files
126           YAML                -  optimized for human readability
127

EXAMPLES

129   Config structures
130       A very simple configuration looks like:
131
132           $log->config(config => {
133               file => {
134                   alias    => 'file1',
135                   filename => 'file1.log',
136                   maxlevel => 'info',
137                   minlevel => 'warn',
138               },
139               screen => {
140                   alias    => 'screen1',
141                   maxlevel => 'debug',
142                   minlevel => 'emerg',
143               }
144           });
145
146       Now, if you want to add another file-output then you can pass the
147       outputs with a array reference:
148
149           $log->config(config => {
150               file => [
151                   {
152                       alias    => 'file1,
153                       filename => 'file1.log',
154                       maxlevel => 'info',
155                       minlevel => 'warn',
156                   },
157                   {
158                       alias    => 'file2',
159                       filename => 'file2.log',
160                       maxlevel => 'error',
161                       minlevel => 'emergency',
162                   }
163               ],
164               screen => {
165                   alias    => 'screen1',
166                   maxlevel => 'debug',
167                   minlevel => 'emerg',
168               },
169           });
170
171       It's also possible to pass the outputs as a hash reference.  The hash
172       keys "file1" and "file2" will be used as aliases.
173
174           $log->config(config => {
175               file => {
176                   file1 => {
177                       filename => 'file1.log',
178                       maxlevel => 'info',
179                       minlevel => 'warn',
180                   },
181                   file2 => {
182                       filename => 'file2.log',
183                       maxlevel => 'error',
184                       minlevel => 'emergency',
185                   }
186               },
187               screen => {
188                   alias    => 'screen1',
189                   maxlevel => 'debug',
190                   minlevel => 'emerg',
191               },
192           });
193
194       If you pass the configuration with the alias as a hash key then it's
195       also possible to pass a section called "default". The options from this
196       section will be used as defaults.
197
198           $log->config(config => {
199               file => {
200                   default => { # defaults for all file-outputs
201                       mode    => 'append',
202                   },
203                   file1 => {
204                       filename => 'file1.log',
205                       maxlevel => 'info',
206                       minlevel => 'warn',
207                   },
208                   file2 => {
209                       filename => 'file2.log',
210                       maxlevel => 'error',
211                       minlevel => 'emergency',
212                   }
213               },
214               screen => {
215                   alias    => 'screen1',
216                   maxlevel => 'debug',
217                   minlevel => 'emerg',
218               },
219           });
220
221   Examples for the config plugins
222       Config::General
223
224           <file>
225               alias = file1
226               fileopen = 1
227               reopen = 1
228               permissions = 0640
229               maxlevel = info
230               minlevel = warn
231               mode = append
232               timeformat = %b %d %H:%M:%S
233               debug_mode = 2
234               filename = example.log
235               message_layout = '%T %H[%P] [%L] %S: %m'
236           </file>
237
238       Or
239
240           <file>
241               <file1>
242                   fileopen = 1
243                   reopen = 1
244                   permissions = 0640
245                   maxlevel = info
246                   minlevel = warn
247                   mode = append
248                   timeformat = %b %d %H:%M:%S
249                   debug_mode = 2
250                   filename = example.log
251                   message_layout = '%T %H[%P] [%L] %S: %m'
252               </file1>
253           </file>
254
255       YAML
256
257           ---
258           file:
259             alias: file1
260             debug_mode: 2
261             filename: example.log
262             fileopen: 1
263             maxlevel: info
264             minlevel: warn
265             mode: append
266             permissions: 0640
267             message_layout: '%T %H[%P] [%L] %S: %m'
268             reopen: 1
269             timeformat: '%b %d %H:%M:%S'
270
271       Or
272
273           ---
274           file:
275             file1:
276               debug_mode: 2
277               filename: example.log
278               fileopen: 1
279               maxlevel: info
280               minlevel: warn
281               mode: append
282               permissions: 0640
283               message_layout: '%T %H[%P] [%L] %S: %m'
284               reopen: 1
285               timeformat: '%b %d %H:%M:%S'
286
287       Config::Properties
288
289           file.alias = file1
290           file.reopen = 1
291           file.fileopen = 1
292           file.maxlevel = info
293           file.minlevel = warn
294           file.permissions = 0640
295           file.mode = append
296           file.timeformat = %b %d %H:%M:%S
297           file.debug_mode = 2
298           file.filename = example.log
299           file.message_layout = '%T %H[%P] [%L] %S: %m'
300
301       Or
302
303           file.file1.alias = file1
304           file.file1.reopen = 1
305           file.file1.fileopen = 1
306           file.file1.maxlevel = info
307           file.file1.minlevel = warn
308           file.file1.permissions = 0640
309           file.file1.mode = append
310           file.file1.timeformat = %b %d %H:%M:%S
311           file.file1.debug_mode = 2
312           file.file1.filename = example.log
313           file.file1.message_layout = '%T %H[%P] [%L] %S: %m'
314

PREREQUISITES

316           Carp
317           Params::Validate
318

EXPORTS

320       No exports.
321

REPORT BUGS

323       Please report all bugs to <jschulz.cpan(at)bloonix.de>.
324
325       If you send me a mail then add Log::Handler into the subject.
326

AUTHOR

328       Jonny Schulz <jschulz.cpan(at)bloonix.de>.
329
331       Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
332
333       This program is free software; you can redistribute it and/or modify it
334       under the same terms as Perl itself.
335
336
337
338perl v5.32.0                      2020-07-28           Log::Handler::Config(3)
Impressum