1Appender::Limit(3) User Contributed Perl Documentation Appender::Limit(3)
2
3
4
6 Log::Log4perl::Appender::Limit - Limit message delivery via block
7 period
8
10 use Log::Log4perl qw(:easy);
11
12 my $conf = qq(
13 log4perl.category = WARN, Limiter
14
15 # Email appender
16 log4perl.appender.Mailer = Log::Dispatch::Email::MailSend
17 log4perl.appender.Mailer.to = drone\@pageme.com
18 log4perl.appender.Mailer.subject = Something's broken!
19 log4perl.appender.Mailer.buffered = 0
20 log4perl.appender.Mailer.layout = PatternLayout
21 log4perl.appender.Mailer.layout.ConversionPattern=%d %m %n
22
23 # Limiting appender, using the email appender above
24 log4perl.appender.Limiter = Log::Log4perl::Appender::Limit
25 log4perl.appender.Limiter.appender = Mailer
26 log4perl.appender.Limiter.block_period = 3600
27 );
28
29 Log::Log4perl->init(\$conf);
30 WARN("This message will be sent immediately.");
31 WARN("This message will be delayed by one hour.");
32 sleep(3601);
33 WARN("This message plus the last one will be sent now, seperately.");
34
36 "appender"
37 Specifies the name of the appender used by the limiter. The
38 appender specified must be defined somewhere in the configuration
39 file, not necessarily before the definition of
40 "Log::Log4perl::Appender::Limit".
41
42 "block_period"
43 Period in seconds between delivery of messages. If messages arrive
44 in between, they will be either saved (if "accumulate" is set to a
45 true value) or discarded (if "accumulate" isn't set).
46
47 "persistent"
48 File name in which "Log::Log4perl::Appender::Limit" persistently
49 stores delivery times. If omitted, the appender will have no
50 recollection of what happened when the program restarts.
51
52 "max_until_flushed"
53 Maximum number of accumulated messages. If exceeded, the appender
54 flushes all messages, regardless if the interval set in
55 "block_period" has passed or not. Don't mix with
56 "max_until_discarded".
57
58 "max_until_discarded"
59 Maximum number of accumulated messages. If exceeded, the appender
60 will simply discard additional messages, waiting for "block_period"
61 to expire to flush all accumulated messages. Don't mix with
62 "max_until_flushed".
63
64 "appender_method_on_flush"
65 Optional method name to be called on the appender attached to the
66 limiter when messages are flushed. For example, to have the sample
67 code in the SYNOPSIS section bundle buffered emails into one,
68 change the mailer's "buffered" parameter to 1 and set the limiters
69 "appender_method_on_flush" value to the string "flush":
70
71 log4perl.category = WARN, Limiter
72
73 # Email appender
74 log4perl.appender.Mailer = Log::Dispatch::Email::MailSend
75 log4perl.appender.Mailer.to = drone\@pageme.com
76 log4perl.appender.Mailer.subject = Something's broken!
77 log4perl.appender.Mailer.buffered = 1
78 log4perl.appender.Mailer.layout = PatternLayout
79 log4perl.appender.Mailer.layout.ConversionPattern=%d %m %n
80
81 # Limiting appender, using the email appender above
82 log4perl.appender.Limiter = Log::Log4perl::Appender::Limit
83 log4perl.appender.Limiter.appender = Mailer
84 log4perl.appender.Limiter.block_period = 3600
85 log4perl.appender.Limiter.appender_method_on_flush = flush
86
87 This will cause the mailer to buffer messages and wait for
88 "flush()" to send out the whole batch. The limiter will then call
89 the appender's "flush()" method when it's own buffer gets flushed
90 out.
91
92 If the appender attached to "Limit" uses "PatternLayout" with a
93 timestamp specifier, you will notice that the message timestamps are
94 reflecting the original log event, not the time of the message
95 rendering in the attached appender. Major trickery has been applied to
96 accomplish this (Cough!).
97
99 "Log::Log4perl::Appender::Limit" is a composite appender. Unlike other
100 appenders, it doesn't log any messages, it just passes them on to its
101 attached sub-appender. For this reason, it doesn't need a layout
102 (contrary to regular appenders). If it defines none, messages are
103 passed on unaltered.
104
105 Custom filters are also applied to the composite appender only. They
106 are not applied to the sub-appender. Same applies to appender
107 thresholds. This behaviour might change in the future.
108
110 Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
111 <cpan@goess.org>.
112
113 This library is free software; you can redistribute it and/or modify it
114 under the same terms as Perl itself.
115
117 Please contribute patches to the project on Github:
118
119 http://github.com/mschilli/log4perl
120
121 Send bug reports or requests for enhancements to the authors via our
122
123 MAILING LIST (questions, bug reports, suggestions/patches):
124 log4perl-devel@lists.sourceforge.net
125
126 Authors (please contact them via the list above, not directly): Mike
127 Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
128
129 Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
130 Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
131 Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
132 Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David
133 Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
134 Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
135 Thegler, David Viner, Mac Yang.
136
137
138
139perl v5.34.0 2021-07-22 Appender::Limit(3)