1Appender::Buffer(3) User Contributed Perl Documentation Appender::Buffer(3)
2
3
4
6 Log::Log4perl::Appender::Buffer - Buffering Appender
7
9 use Log::Log4perl qw(:easy);
10
11 my $conf = qq(
12 log4perl.category = DEBUG, Buffer
13
14 # Regular Screen Appender
15 log4perl.appender.Screen = Log::Log4perl::Appender::Screen
16 log4perl.appender.Screen.stdout = 1
17 log4perl.appender.Screen.layout = PatternLayout
18 log4perl.appender.Screen.layout.ConversionPattern = %d %p %c %m %n
19
20 # Buffering appender, using the appender above as outlet
21 log4perl.appender.Buffer = Log::Log4perl::Appender::Buffer
22 log4perl.appender.Buffer.appender = Screen
23 log4perl.appender.Buffer.trigger_level = ERROR
24 );
25
26 Log::Log4perl->init(\$conf);
27
28 DEBUG("This message gets buffered.");
29 INFO("This message gets buffered also.");
30
31 # Time passes. Nothing happens. But then ...
32
33 print "It's GO time!!!\n";
34
35 ERROR("This message triggers a buffer flush.");
36
38 "Log::Log4perl::Appender::Buffer" takes these arguments:
39
40 "appender"
41 Specifies the name of the appender it buffers messages for. The
42 appender specified must be defined somewhere in the configuration
43 file, not necessarily before the definition of
44 "Log::Log4perl::Appender::Buffer".
45
46 "max_messages"
47 Specifies the maximum number of messages the appender will hold in
48 its ring buffer. "max_messages" is optional. By default,
49 "Log::Log4perl::Appender::Buffer" will not limit the number of
50 messages buffered. This might be undesirable in long-running
51 processes accumulating lots of messages before a flush happens. If
52 "max_messages" is set to a numeric value,
53 "Log::Log4perl::Appender::Buffer" will displace old messages in its
54 buffer to make room if the buffer is full.
55
56 "trigger_level"
57 If trigger_level is set to one of Log4perl's levels (see
58 Log::Log4perl::Level), a "trigger" function will be defined
59 internally to flush the buffer if a message with a priority of
60 $level or higher comes along. This is just a convenience function.
61 Defining
62
63 log4perl.appender.Buffer.trigger_level = ERROR
64
65 is equivalent to creating a trigger function like
66
67 log4perl.appender.Buffer.trigger = sub { \
68 my($self, $params) = @_; \
69 return $params->{log4p_level} >= \
70 $Log::Log4perl::Level::ERROR; }
71
72 See the next section for defining generic trigger functions.
73
74 "trigger"
75 "trigger" holds a reference to a subroutine, which
76 "Log::Log4perl::Appender::Buffer" will call on every incoming
77 message with the same parameters as the appender's "log()" method:
78
79 my($self, $params) = @_;
80
81 $params references a hash containing the message priority (key
82 "l4p_level"), the message category (key "l4p_category") and the
83 content of the message (key "message").
84
85 If the subroutine returns 1, it will trigger a flush of buffered
86 messages.
87
88 Shortcut
89
91 "Log::Log4perl::Appender::Buffer" is a composite appender. Unlike
92 other appenders, it doesn't log any messages, it just passes them on to
93 its attached sub-appender. For this reason, it doesn't need a layout
94 (contrary to regular appenders). If it defines none, messages are
95 passed on unaltered.
96
97 Custom filters are also applied to the composite appender only. They
98 are not applied to the sub-appender. Same applies to appender
99 thresholds. This behaviour might change in the future.
100
102 Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
103 <cpan@goess.org>.
104
105 This library is free software; you can redistribute it and/or modify it
106 under the same terms as Perl itself.
107
109 Please contribute patches to the project on Github:
110
111 http://github.com/mschilli/log4perl
112
113 Send bug reports or requests for enhancements to the authors via our
114
115 MAILING LIST (questions, bug reports, suggestions/patches):
116 log4perl-devel@lists.sourceforge.net
117
118 Authors (please contact them via the list above, not directly): Mike
119 Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
120
121 Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
122 Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
123 Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
124 Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David
125 Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
126 Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
127 Thegler, David Viner, Mac Yang.
128
129
130
131perl v5.34.0 2022-01-21 Appender::Buffer(3)