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 flush()
88 to send out the whole batch. The limiter will then call the
89 appender's flush() method when it's own buffer gets flushed out.
90
91 If the appender attached to "Limit" uses "PatternLayout" with a
92 timestamp specifier, you will notice that the message timestamps are
93 reflecting the original log event, not the time of the message
94 rendering in the attached appender. Major trickery has been applied to
95 accomplish this (Cough!).
96
98 "Log::Log4perl::Appender::Limit" is a composite appender. Unlike other
99 appenders, it doesn't log any messages, it just passes them on to its
100 attached sub-appender. For this reason, it doesn't need a layout
101 (contrary to regular appenders). If it defines none, messages are
102 passed on unaltered.
103
104 Custom filters are also applied to the composite appender only. They
105 are not applied to the sub-appender. Same applies to appender
106 thresholds. This behaviour might change in the future.
107
109 Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
110 <cpan@goess.org>.
111
112 This library is free software; you can redistribute it and/or modify it
113 under the same terms as Perl itself.
114
116 Please contribute patches to the project on Github:
117
118 http://github.com/mschilli/log4perl
119
120 Send bug reports or requests for enhancements to the authors via our
121
122 MAILING LIST (questions, bug reports, suggestions/patches):
123 log4perl-devel@lists.sourceforge.net
124
125 Authors (please contact them via the list above, not directly): Mike
126 Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
127
128 Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
129 Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
130 Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
131 Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David
132 Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
133 Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
134 Thegler, David Viner, Mac Yang.
135
136
137
138perl v5.36.0 2023-01-20 Appender::Limit(3)