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 mes‐
50 sages buffered. This might be undesirable in long-running processes
51 accumulating lots of messages before a flush happens. If "max_mes‐
52 sages" is set to a numeric value, "Log::Log4perl::Appender::Buffer"
53 will displace old messages in its buffer to make room if the buffer
54 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 inter‐
59 nally to flush the buffer if a message with a priority of $level or
60 higher comes along. This is just a convenience function. Defining
61
62 log4perl.appender.Buffer.trigger_level = ERROR
63
64 is equivalent to creating a trigger function like
65
66 log4perl.appender.Buffer.trigger = sub { \
67 my($self, $params) = @_; \
68 return $params->{log4p_level} >= \
69 $Log::Log4perl::Level::ERROR; }
70
71 See the next section for defining generic trigger functions.
72
73 "trigger"
74 "trigger" holds a reference to a subroutine, which
75 "Log::Log4perl::Appender::Buffer" will call on every incoming mes‐
76 sage with the same parameters as the appender's "log()" method:
77
78 my($self, $params) = @_;
79
80 $params references a hash containing the message priority (key
81 "l4p_level"), the message category (key "l4p_category") and the
82 content of the message (key "message").
83
84 If the subroutine returns 1, it will trigger a flush of buffered
85 messages.
86
87 Shortcut
88
90 "Log::Log4perl::Appender::Buffer" is a composite appender. Unlike
91 other appenders, it doesn't log any messages, it just passes them on to
92 its attached sub-appender. For this reason, it doesn't need a layout
93 (contrary to regular appenders). If it defines none, messages are
94 passed on unaltered.
95
96 Custom filters are also applied to the composite appender only. They
97 are not applied to the sub-appender. Same applies to appender thresh‐
98 olds. This behaviour might change in the future.
99
101 Copyright 2004 by Mike Schilli, all rights reserved. This program is
102 free software, you can redistribute it and/or modify it under the same
103 terms as Perl itself.
104
106 2004, Mike Schilli <m@perlmeister.com>
107
108
109
110perl v5.8.8 2002-07-10 Appender::Buffer(3)