1Appender::Socket(3)   User Contributed Perl Documentation  Appender::Socket(3)
2
3
4

NAME

6       Log::Log4perl::Appender::Socket - Log to a socket
7

SYNOPSIS

9           use Log::Log4perl::Appender::Socket;
10
11           my $appender = Log::Log4perl::Appender::Socket->new(
12             PeerAddr => "server.foo.com",
13             PeerPort => 1234,
14           );
15
16           $appender->log(message => "Log me\n");
17

DESCRIPTION

19       This is a simple appender for writing to a socket. It relies on
20       IO::Socket::INET and offers all parameters this module offers.
21
22       Upon destruction of the object, pending messages will be flushed and
23       the socket will be closed.
24
25       If the appender cannot contact the server during the initialization
26       phase (while running the constructor "new"), it will "die()".
27
28       If the appender fails to log a message because the socket's "send()"
29       method fails (most likely because the server went down), it will try to
30       reconnect once. If it succeeds, the message will be sent.  If the
31       reconnect fails, a warning is sent to STDERR and the "log()" method
32       returns, discarding the message.
33
34       If the option "silent_recovery" is given to the constructor and set to
35       a true value, the behaviour is different: If the socket connection
36       can't be established at initialization time, a single warning is
37       issued.  Every log attempt will then try to establish the connection
38       and discard the message silently if it fails.  If you don't even want
39       the warning, set the "no_warning" option to a true value.
40
41       Connecting at initialization time may not be the best option when
42       running under Apache1 Apache2/prefork, because the parent process
43       creates the socket and the connections are shared among the forked
44       children--all the children writing to the same socket could intermingle
45       messages.  So instead of that, you can use "defer_connection" which
46       will put off making the connection until the first log message is sent.
47

EXAMPLE

49       Write a server quickly using the IO::Socket::INET module:
50
51           use IO::Socket::INET;
52
53           my $sock = IO::Socket::INET->new(
54               Listen    => 5,
55               LocalAddr => 'localhost',
56               LocalPort => 12345,
57               Proto     => 'tcp');
58
59           while(my $client = $sock->accept()) {
60               print "Client connected\n";
61               while(<$client>) {
62                   print "$_\n";
63               }
64           }
65
66       Start it and then run the following script as a client:
67
68           use Log::Log4perl qw(:easy);
69
70           my $conf = q{
71               log4perl.category                  = WARN, Socket
72               log4perl.appender.Socket           = Log::Log4perl::Appender::Socket
73               log4perl.appender.Socket.PeerAddr  = localhost
74               log4perl.appender.Socket.PeerPort  = 12345
75               log4perl.appender.Socket.layout    = SimpleLayout
76           };
77
78           Log::Log4perl->init(\$conf);
79
80           sleep(2);
81
82           for(1..10) {
83               ERROR("Quack!");
84               sleep(5);
85           }
86

LICENSE

88       Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
89       <cpan@goess.org>.
90
91       This library is free software; you can redistribute it and/or modify it
92       under the same terms as Perl itself.
93

AUTHOR

95       Please contribute patches to the project on Github:
96
97           http://github.com/mschilli/log4perl
98
99       Send bug reports or requests for enhancements to the authors via our
100
101       MAILING LIST (questions, bug reports, suggestions/patches):
102       log4perl-devel@lists.sourceforge.net
103
104       Authors (please contact them via the list above, not directly): Mike
105       Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
106
107       Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
108       Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
109       Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
110       Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier  David
111       Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
112       Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
113       Thegler, David Viner, Mac Yang.
114
115
116
117perl v5.32.1                      2021-02-08               Appender::Socket(3)
Impressum