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.
39

EXAMPLE

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

AUTHOR

80       Mike Schilli <log4perl@perlmeister.com>, 2003
81
82
83
84perl v5.8.8                       2002-07-10               Appender::Socket(3)
Impressum