Update Term::UI to 0.18
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / Syslog.pm
CommitLineData
a0d0e21e 1package Sys::Syslog;
8168e71f 2use strict;
89c3c464 3use warnings::register;
8168e71f 4use Carp;
a650b841 5use Fcntl qw(O_WRONLY);
07b7e4bc 6use File::Basename;
6e4ef777 7use POSIX qw(strftime setlocale LC_TIME);
8use Socket ':all';
d329efa2 9require 5.005;
a0d0e21e 10require Exporter;
a0d0e21e 11
89c3c464 12{ no strict 'vars';
d329efa2 13 $VERSION = '0.21';
89c3c464 14 @ISA = qw(Exporter);
942974c1 15
89c3c464 16 %EXPORT_TAGS = (
4b035b3d 17 standard => [qw(openlog syslog closelog setlogmask)],
18 extended => [qw(setlogsock)],
19 macros => [
20 # levels
21 qw(
22 LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR
23 LOG_INFO LOG_NOTICE LOG_WARNING
24 ),
25
a650b841 26 # standard facilities
4b035b3d 27 qw(
a650b841 28 LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN
29 LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
30 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS
31 LOG_SYSLOG LOG_USER LOG_UUCP
32 ),
33 # Mac OS X specific facilities
34 qw( LOG_INSTALL LOG_LAUNCHD LOG_NETINFO LOG_RAS LOG_REMOTEAUTH ),
35 # modern BSD specific facilities
36 qw( LOG_CONSOLE LOG_NTP LOG_SECURITY ),
37 # IRIX specific facilities
38 qw( LOG_AUDIT LOG_LFMT ),
4b035b3d 39
40 # options
41 qw(
42 LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR
43 ),
44
45 # others macros
46 qw(
47 LOG_FACMASK LOG_NFACILITIES LOG_PRIMASK
48 LOG_MASK LOG_UPTO
49 ),
50 ],
89c3c464 51 );
942974c1 52
89c3c464 53 @EXPORT = (
07b7e4bc 54 @{$EXPORT_TAGS{standard}},
89c3c464 55 );
942974c1 56
89c3c464 57 @EXPORT_OK = (
07b7e4bc 58 @{$EXPORT_TAGS{extended}},
59 @{$EXPORT_TAGS{macros}},
89c3c464 60 );
61
62 eval {
63 require XSLoader;
64 XSLoader::load('Sys::Syslog', $VERSION);
65 1
66 } or do {
67 require DynaLoader;
68 push @ISA, 'DynaLoader';
69 bootstrap Sys::Syslog $VERSION;
70 };
71}
72
73
74#
75# Public variables
76#
a650b841 77use vars qw($host); # host to send syslog messages to (see notes at end)
89c3c464 78
79#
80# Global variables
81#
a650b841 82use vars qw($facility);
89c3c464 83my $connected = 0; # flag to indicate if we're connected or not
84my $syslog_send; # coderef of the function used to send messages
85my $syslog_path = undef; # syslog path for "stream" and "unix" mechanisms
a650b841 86my $syslog_xobj = undef; # if defined, holds the external object used to send messages
89c3c464 87my $transmit_ok = 0; # flag to indicate if the last message was transmited
88my $current_proto = undef; # current mechanism used to transmit messages
89my $ident = ''; # identifiant prepended to each message
a650b841 90$facility = ''; # current facility
89c3c464 91my $maskpri = LOG_UPTO(&LOG_DEBUG); # current log mask
92
93my %options = (
94 ndelay => 0,
95 nofatal => 0,
96 nowait => 0,
97 pid => 0,
942974c1 98);
a0d0e21e 99
a650b841 100# Default is now to first use the native mechanism, so Perl programs
d329efa2 101# behave like other normal Unix programs, then try other mechanisms.
102my @connectMethods = qw(native tcp udp unix pipe stream console);
dbfdd438 103if ($^O =~ /^(freebsd|linux)$/) {
104 @connectMethods = grep { $_ ne 'udp' } @connectMethods;
105}
a650b841 106
107# use EventLog on Win32
108my $is_Win32 = $^O =~ /Win32/i;
109eval "use Sys::Syslog::Win32";
110
111if (not $@) {
112 unshift @connectMethods, 'eventlog';
113} elsif ($is_Win32) {
114 warn $@;
115}
116
23642f4b 117my @defaultMethods = @connectMethods;
89c3c464 118my @fallbackMethods = ();
8168e71f 119
89c3c464 120# coderef for a nicer handling of errors
121my $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak;
5be1dfc7 122
5be1dfc7 123
89c3c464 124sub AUTOLOAD {
125 # This AUTOLOAD is used to 'autoload' constants from the constant()
126 # XS function.
127 no strict 'vars';
128 my $constname;
129 ($constname = $AUTOLOAD) =~ s/.*:://;
130 croak "Sys::Syslog::constant() not defined" if $constname eq 'constant';
131 my ($error, $val) = constant($constname);
a650b841 132 croak $error if $error;
89c3c464 133 no strict 'refs';
134 *$AUTOLOAD = sub { $val };
135 goto &$AUTOLOAD;
136}
5be1dfc7 137
5be1dfc7 138
89c3c464 139sub openlog {
140 ($ident, my $logopt, $facility) = @_;
8168e71f 141
a650b841 142 # default values
143 $ident ||= basename($0) || getlogin() || getpwuid($<) || 'syslog';
144 $logopt ||= '';
145 $facility ||= LOG_USER();
146
89c3c464 147 for my $opt (split /\b/, $logopt) {
148 $options{$opt} = 1 if exists $options{$opt}
149 }
5be1dfc7 150
89c3c464 151 $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak;
152 return 1 unless $options{ndelay};
153 connect_log();
154}
5be1dfc7 155
89c3c464 156sub closelog {
157 $facility = $ident = '';
158 disconnect_log();
159}
8168e71f 160
89c3c464 161sub setlogmask {
162 my $oldmask = $maskpri;
163 $maskpri = shift unless $_[0] == 0;
164 $oldmask;
165}
07b7e4bc 166
89c3c464 167sub setlogsock {
168 my $setsock = shift;
169 $syslog_path = shift;
170 disconnect_log() if $connected;
171 $transmit_ok = 0;
172 @fallbackMethods = ();
173 @connectMethods = @defaultMethods;
942974c1 174
89c3c464 175 if (ref $setsock eq 'ARRAY') {
176 @connectMethods = @$setsock;
942974c1 177
89c3c464 178 } elsif (lc $setsock eq 'stream') {
a650b841 179 if (not defined $syslog_path) {
89c3c464 180 my @try = qw(/dev/log /dev/conslog);
a650b841 181
182 if (length &_PATH_LOG) { # Undefined _PATH_LOG is "".
89c3c464 183 unshift @try, &_PATH_LOG;
184 }
a650b841 185
89c3c464 186 for my $try (@try) {
187 if (-w $try) {
188 $syslog_path = $try;
189 last;
190 }
191 }
a650b841 192
193 if (not defined $syslog_path) {
194 warnings::warnif "stream passed to setlogsock, but could not find any device";
195 return undef
196 }
89c3c464 197 }
a650b841 198
199 if (not -w $syslog_path) {
07b7e4bc 200 warnings::warnif "stream passed to setlogsock, but $syslog_path is not writable";
89c3c464 201 return undef;
202 } else {
a650b841 203 @connectMethods = qw(stream);
89c3c464 204 }
942974c1 205
89c3c464 206 } elsif (lc $setsock eq 'unix') {
8edeb3ad 207 if (length _PATH_LOG() || (defined $syslog_path && -w $syslog_path)) {
208 $syslog_path = _PATH_LOG() unless defined $syslog_path;
a650b841 209 @connectMethods = qw(unix);
89c3c464 210 } else {
211 warnings::warnif 'unix passed to setlogsock, but path not available';
212 return undef;
213 }
8168e71f 214
d329efa2 215 } elsif (lc $setsock eq 'pipe') {
216 for my $path ($syslog_path, &_PATH_LOG, "/dev/log") {
217 next unless defined $path and length $path and -w $path;
218 $syslog_path = $path;
219 last
220 }
221
222 if (not $syslog_path) {
223 warnings::warnif "pipe passed to setlogsock, but path not available";
224 return undef
225 }
226
227 @connectMethods = qw(pipe);
228
89c3c464 229 } elsif (lc $setsock eq 'native') {
a650b841 230 @connectMethods = qw(native);
231
232 } elsif (lc $setsock eq 'eventlog') {
233 if (eval "use Win32::EventLog; 1") {
234 @connectMethods = qw(eventlog);
235 } else {
d329efa2 236 warnings::warnif "eventlog passed to setlogsock, but operating system isn't Win32-compatible";
237 return undef;
a650b841 238 }
8168e71f 239
89c3c464 240 } elsif (lc $setsock eq 'tcp') {
241 if (getservbyname('syslog', 'tcp') || getservbyname('syslogng', 'tcp')) {
a650b841 242 @connectMethods = qw(tcp);
89c3c464 243 } else {
244 warnings::warnif "tcp passed to setlogsock, but tcp service unavailable";
245 return undef;
246 }
942974c1 247
89c3c464 248 } elsif (lc $setsock eq 'udp') {
249 if (getservbyname('syslog', 'udp')) {
a650b841 250 @connectMethods = qw(udp);
89c3c464 251 } else {
252 warnings::warnif "udp passed to setlogsock, but udp service unavailable";
253 return undef;
254 }
942974c1 255
89c3c464 256 } elsif (lc $setsock eq 'inet') {
257 @connectMethods = ( 'tcp', 'udp' );
942974c1 258
89c3c464 259 } elsif (lc $setsock eq 'console') {
a650b841 260 @connectMethods = qw(console);
942974c1 261
89c3c464 262 } else {
d329efa2 263 croak "Invalid argument passed to setlogsock; must be 'stream', 'pipe', ",
264 "'unix', 'native', 'eventlog', 'tcp', 'udp' or 'inet'"
89c3c464 265 }
942974c1 266
89c3c464 267 return 1;
268}
942974c1 269
89c3c464 270sub syslog {
271 my $priority = shift;
272 my $mask = shift;
273 my ($message, $buf);
274 my (@words, $num, $numpri, $numfac, $sum);
275 my $failed = undef;
276 my $fail_time = undef;
8edeb3ad 277 my $error = $!;
8168e71f 278
a650b841 279 # if $ident is undefined, it means openlog() wasn't previously called
280 # so do it now in order to have sensible defaults
281 openlog() unless $ident;
282
283 local $facility = $facility; # may need to change temporarily.
8168e71f 284
89c3c464 285 croak "syslog: expecting argument \$priority" unless defined $priority;
286 croak "syslog: expecting argument \$format" unless defined $mask;
5be1dfc7 287
8edeb3ad 288 @words = split(/\W+/, $priority, 2); # Allow "level" or "level|facility".
89c3c464 289 undef $numpri;
290 undef $numfac;
5be1dfc7 291
89c3c464 292 foreach (@words) {
8edeb3ad 293 $num = xlate($_); # Translate word to number.
89c3c464 294 if ($num < 0) {
295 croak "syslog: invalid level/facility: $_"
296 }
297 elsif ($num <= &LOG_PRIMASK) {
298 croak "syslog: too many levels given: $_" if defined $numpri;
299 $numpri = $num;
300 return 0 unless LOG_MASK($numpri) & $maskpri;
301 }
302 else {
303 croak "syslog: too many facilities given: $_" if defined $numfac;
304 $facility = $_;
305 $numfac = $num;
306 }
307 }
5be1dfc7 308
89c3c464 309 croak "syslog: level must be given" unless defined $numpri;
942974c1 310
89c3c464 311 if (not defined $numfac) { # Facility not specified in this call.
312 $facility = 'user' unless $facility;
313 $numfac = xlate($facility);
314 }
3d256c0f 315
89c3c464 316 connect_log() unless $connected;
8168e71f 317
89c3c464 318 if ($mask =~ /%m/) {
07b7e4bc 319 # escape percent signs for sprintf()
8edeb3ad 320 $error =~ s/%/%%/g if @_;
a650b841 321 # replace %m with $error, if preceded by an even number of percent signs
8edeb3ad 322 $mask =~ s/(?<!%)((?:%%)*)%m/$1$error/g;
89c3c464 323 }
5be1dfc7 324
89c3c464 325 $mask .= "\n" unless $mask =~ /\n$/;
326 $message = @_ ? sprintf($mask, @_) : $mask;
942974c1 327
d329efa2 328 # See CPAN-RT#24431. Opened on Apple Radar as bug #4944407 on 2007.01.21
329 chomp $message if $^O =~ /darwin/;
330
331 if ($current_proto eq 'native') {
89c3c464 332 $buf = $message;
942974c1 333
a650b841 334 }
335 elsif ($current_proto eq 'eventlog') {
336 $buf = $message;
337 }
338 else {
89c3c464 339 my $whoami = $ident;
89c3c464 340 $whoami .= "[$$]" if $options{pid};
942974c1 341
89c3c464 342 $sum = $numpri + $numfac;
343 my $oldlocale = setlocale(LC_TIME);
344 setlocale(LC_TIME, 'C');
345 my $timestamp = strftime "%b %e %T", localtime;
346 setlocale(LC_TIME, $oldlocale);
347 $buf = "<$sum>$timestamp $whoami: $message\0";
348 }
942974c1 349
89c3c464 350 # it's possible that we'll get an error from sending
351 # (e.g. if method is UDP and there is no UDP listener,
352 # then we'll get ECONNREFUSED on the send). So what we
353 # want to do at this point is to fallback onto a different
354 # connection method.
355 while (scalar @fallbackMethods || $syslog_send) {
356 if ($failed && (time - $fail_time) > 60) {
357 # it's been a while... maybe things have been fixed
358 @fallbackMethods = ();
359 disconnect_log();
360 $transmit_ok = 0; # make it look like a fresh attempt
361 connect_log();
362 }
942974c1 363
89c3c464 364 if ($connected && !connection_ok()) {
365 # Something was OK, but has now broken. Remember coz we'll
366 # want to go back to what used to be OK.
367 $failed = $current_proto unless $failed;
368 $fail_time = time;
369 disconnect_log();
370 }
942974c1 371
89c3c464 372 connect_log() unless $connected;
373 $failed = undef if ($current_proto && $failed && $current_proto eq $failed);
942974c1 374
89c3c464 375 if ($syslog_send) {
a650b841 376 if ($syslog_send->($buf, $numpri, $numfac)) {
89c3c464 377 $transmit_ok++;
378 return 1;
379 }
380 # typically doesn't happen, since errors are rare from write().
381 disconnect_log();
382 }
383 }
384 # could not send, could not fallback onto a working
385 # connection method. Lose.
386 return 0;
387}
942974c1 388
89c3c464 389sub _syslog_send_console {
390 my ($buf) = @_;
391 chop($buf); # delete the NUL from the end
392 # The console print is a method which could block
393 # so we do it in a child process and always return success
394 # to the caller.
395 if (my $pid = fork) {
942974c1 396
89c3c464 397 if ($options{nowait}) {
398 return 1;
399 } else {
400 if (waitpid($pid, 0) >= 0) {
401 return ($? >> 8);
402 } else {
403 # it's possible that the caller has other
404 # plans for SIGCHLD, so let's not interfere
405 return 1;
406 }
407 }
408 } else {
409 if (open(CONS, ">/dev/console")) {
410 my $ret = print CONS $buf . "\r"; # XXX: should this be \x0A ?
411 exit $ret if defined $pid;
412 close CONS;
413 }
414 exit if defined $pid;
415 }
416}
942974c1 417
89c3c464 418sub _syslog_send_stream {
419 my ($buf) = @_;
420 # XXX: this only works if the OS stream implementation makes a write
421 # look like a putmsg() with simple header. For instance it works on
422 # Solaris 8 but not Solaris 7.
423 # To be correct, it should use a STREAMS API, but perl doesn't have one.
424 return syswrite(SYSLOG, $buf, length($buf));
425}
942974c1 426
d329efa2 427sub _syslog_send_pipe {
428 my ($buf) = @_;
429 return print SYSLOG $buf;
430}
431
89c3c464 432sub _syslog_send_socket {
433 my ($buf) = @_;
434 return syswrite(SYSLOG, $buf, length($buf));
435 #return send(SYSLOG, $buf, 0);
436}
942974c1 437
89c3c464 438sub _syslog_send_native {
439 my ($buf, $numpri) = @_;
a650b841 440 syslog_xs($numpri, $buf);
441 return 1;
89c3c464 442}
ce43db9b 443
5be1dfc7 444
89c3c464 445# xlate()
446# -----
447# private function to translate names to numeric values
448#
449sub xlate {
450 my($name) = @_;
451 return $name+0 if $name =~ /^\s*\d+\s*$/;
452 $name = uc $name;
453 $name = "LOG_$name" unless $name =~ /^LOG_/;
454 $name = "Sys::Syslog::$name";
455 # Can't have just eval { &$name } || -1 because some LOG_XXX may be zero.
456 my $value = eval { no strict 'refs'; &$name };
457 defined $value ? $value : -1;
458}
5be1dfc7 459
942974c1 460
89c3c464 461# connect_log()
462# -----------
463# This function acts as a kind of front-end: it tries to connect to
464# a syslog service using the selected methods, trying each one in the
465# selected order.
466#
467sub connect_log {
468 @fallbackMethods = @connectMethods unless scalar @fallbackMethods;
07b7e4bc 469
89c3c464 470 if ($transmit_ok && $current_proto) {
471 # Retry what we were on, because it has worked in the past.
472 unshift(@fallbackMethods, $current_proto);
473 }
07b7e4bc 474
89c3c464 475 $connected = 0;
476 my @errs = ();
477 my $proto = undef;
07b7e4bc 478
89c3c464 479 while ($proto = shift @fallbackMethods) {
480 no strict 'refs';
481 my $fn = "connect_$proto";
482 $connected = &$fn(\@errs) if defined &$fn;
483 last if $connected;
484 }
3d256c0f 485
89c3c464 486 $transmit_ok = 0;
487 if ($connected) {
488 $current_proto = $proto;
a650b841 489 my ($old) = select(SYSLOG); $| = 1; select($old);
89c3c464 490 } else {
491 @fallbackMethods = ();
492 $err_sub->(join "\n\t- ", "no connection to syslog available", @errs);
493 return undef;
494 }
495}
942974c1 496
89c3c464 497sub connect_tcp {
498 my ($errs) = @_;
4b035b3d 499
89c3c464 500 my $tcp = getprotobyname('tcp');
501 if (!defined $tcp) {
502 push @$errs, "getprotobyname failed for tcp";
503 return 0;
504 }
4b035b3d 505
506 my $syslog = getservbyname('syslog', 'tcp');
507 $syslog = getservbyname('syslogng', 'tcp') unless defined $syslog;
89c3c464 508 if (!defined $syslog) {
509 push @$errs, "getservbyname failed for syslog/tcp and syslogng/tcp";
510 return 0;
511 }
942974c1 512
4b035b3d 513 my $addr;
89c3c464 514 if (defined $host) {
4b035b3d 515 $addr = inet_aton($host);
516 if (!$addr) {
89c3c464 517 push @$errs, "can't lookup $host";
518 return 0;
519 }
520 } else {
4b035b3d 521 $addr = INADDR_LOOPBACK;
89c3c464 522 }
4b035b3d 523 $addr = sockaddr_in($syslog, $addr);
942974c1 524
89c3c464 525 if (!socket(SYSLOG, AF_INET, SOCK_STREAM, $tcp)) {
526 push @$errs, "tcp socket: $!";
527 return 0;
528 }
a650b841 529
89c3c464 530 setsockopt(SYSLOG, SOL_SOCKET, SO_KEEPALIVE, 1);
d329efa2 531 if (eval { IPPROTO_TCP() }) {
532 # These constants don't exist in 5.005. They were added in 1999
533 setsockopt(SYSLOG, IPPROTO_TCP(), TCP_NODELAY(), 1);
534 }
4b035b3d 535 if (!connect(SYSLOG, $addr)) {
89c3c464 536 push @$errs, "tcp connect: $!";
537 return 0;
538 }
4b035b3d 539
89c3c464 540 $syslog_send = \&_syslog_send_socket;
4b035b3d 541
89c3c464 542 return 1;
543}
942974c1 544
89c3c464 545sub connect_udp {
546 my ($errs) = @_;
4b035b3d 547
89c3c464 548 my $udp = getprotobyname('udp');
549 if (!defined $udp) {
550 push @$errs, "getprotobyname failed for udp";
551 return 0;
552 }
4b035b3d 553
554 my $syslog = getservbyname('syslog', 'udp');
89c3c464 555 if (!defined $syslog) {
556 push @$errs, "getservbyname failed for syslog/udp";
557 return 0;
558 }
4b035b3d 559
560 my $addr;
89c3c464 561 if (defined $host) {
4b035b3d 562 $addr = inet_aton($host);
563 if (!$addr) {
89c3c464 564 push @$errs, "can't lookup $host";
565 return 0;
566 }
567 } else {
4b035b3d 568 $addr = INADDR_LOOPBACK;
89c3c464 569 }
4b035b3d 570 $addr = sockaddr_in($syslog, $addr);
942974c1 571
89c3c464 572 if (!socket(SYSLOG, AF_INET, SOCK_DGRAM, $udp)) {
573 push @$errs, "udp socket: $!";
574 return 0;
575 }
4b035b3d 576 if (!connect(SYSLOG, $addr)) {
89c3c464 577 push @$errs, "udp connect: $!";
578 return 0;
579 }
4b035b3d 580
89c3c464 581 # We want to check that the UDP connect worked. However the only
582 # way to do that is to send a message and see if an ICMP is returned
583 _syslog_send_socket("");
584 if (!connection_ok()) {
585 push @$errs, "udp connect: nobody listening";
586 return 0;
587 }
4b035b3d 588
89c3c464 589 $syslog_send = \&_syslog_send_socket;
4b035b3d 590
89c3c464 591 return 1;
592}
9903e4c8 593
89c3c464 594sub connect_stream {
595 my ($errs) = @_;
596 # might want syslog_path to be variable based on syslog.h (if only
597 # it were in there!)
8edeb3ad 598 $syslog_path = '/dev/conslog' unless defined $syslog_path;
89c3c464 599 if (!-w $syslog_path) {
600 push @$errs, "stream $syslog_path is not writable";
601 return 0;
602 }
a650b841 603 if (!sysopen(SYSLOG, $syslog_path, 0400, O_WRONLY)) {
89c3c464 604 push @$errs, "stream can't open $syslog_path: $!";
605 return 0;
606 }
607 $syslog_send = \&_syslog_send_stream;
608 return 1;
609}
942974c1 610
d329efa2 611sub connect_pipe {
612 my ($errs) = @_;
613
614 $syslog_path ||= &_PATH_LOG || "/dev/log";
615
616 if (not -w $syslog_path) {
617 push @$errs, "$syslog_path is not writable";
618 return 0;
619 }
620
621 if (not open(SYSLOG, ">$syslog_path")) {
622 push @$errs, "can't write to $syslog_path: $!";
623 return 0;
624 }
625
626 $syslog_send = \&_syslog_send_pipe;
627
628 return 1;
629}
630
89c3c464 631sub connect_unix {
632 my ($errs) = @_;
4b035b3d 633
634 $syslog_path ||= _PATH_LOG() if length _PATH_LOG();
635
636 if (not defined $syslog_path) {
637 push @$errs, "_PATH_LOG not available in syslog.h and no user-supplied socket path";
89c3c464 638 return 0;
639 }
4b035b3d 640
89c3c464 641 if (! -S $syslog_path) {
642 push @$errs, "$syslog_path is not a socket";
643 return 0;
644 }
4b035b3d 645
646 my $addr = sockaddr_un($syslog_path);
647 if (!$addr) {
89c3c464 648 push @$errs, "can't locate $syslog_path";
649 return 0;
650 }
4b035b3d 651 if (!socket(SYSLOG, AF_UNIX, SOCK_STREAM, 0)) {
89c3c464 652 push @$errs, "unix stream socket: $!";
653 return 0;
654 }
a650b841 655
4b035b3d 656 if (!connect(SYSLOG, $addr)) {
657 if (!socket(SYSLOG, AF_UNIX, SOCK_DGRAM, 0)) {
89c3c464 658 push @$errs, "unix dgram socket: $!";
659 return 0;
660 }
4b035b3d 661 if (!connect(SYSLOG, $addr)) {
89c3c464 662 push @$errs, "unix dgram connect: $!";
663 return 0;
664 }
665 }
4b035b3d 666
89c3c464 667 $syslog_send = \&_syslog_send_socket;
4b035b3d 668
89c3c464 669 return 1;
670}
942974c1 671
89c3c464 672sub connect_native {
673 my ($errs) = @_;
674 my $logopt = 0;
5be1dfc7 675
89c3c464 676 # reconstruct the numeric equivalent of the options
677 for my $opt (keys %options) {
678 $logopt += xlate($opt) if $options{$opt}
679 }
942974c1 680
89c3c464 681 eval { openlog_xs($ident, $logopt, xlate($facility)) };
682 if ($@) {
683 push @$errs, $@;
684 return 0;
685 }
942974c1 686
89c3c464 687 $syslog_send = \&_syslog_send_native;
942974c1 688
89c3c464 689 return 1;
690}
6e4ef777 691
a650b841 692sub connect_eventlog {
693 my ($errs) = @_;
694
695 $syslog_xobj = Sys::Syslog::Win32::_install();
696 $syslog_send = \&Sys::Syslog::Win32::_syslog_send;
697
698 return 1;
699}
700
89c3c464 701sub connect_console {
702 my ($errs) = @_;
703 if (!-w '/dev/console') {
704 push @$errs, "console is not writable";
705 return 0;
706 }
707 $syslog_send = \&_syslog_send_console;
708 return 1;
709}
6e4ef777 710
a650b841 711# To test if the connection is still good, we need to check if any
89c3c464 712# errors are present on the connection. The errors will not be raised
713# by a write. Instead, sockets are made readable and the next read
714# would cause the error to be returned. Unfortunately the syslog
715# 'protocol' never provides anything for us to read. But with
716# judicious use of select(), we can see if it would be readable...
717sub connection_ok {
718 return 1 if defined $current_proto and (
719 $current_proto eq 'native' or $current_proto eq 'console'
a650b841 720 or $current_proto eq 'eventlog'
89c3c464 721 );
a650b841 722
89c3c464 723 my $rin = '';
724 vec($rin, fileno(SYSLOG), 1) = 1;
a650b841 725 my $ret = select $rin, undef, $rin, 0.25;
89c3c464 726 return ($ret ? 0 : 1);
727}
942974c1 728
89c3c464 729sub disconnect_log {
730 $connected = 0;
731 $syslog_send = undef;
942974c1 732
a650b841 733 if (defined $current_proto and $current_proto eq 'native') {
734 closelog_xs();
735 return 1;
736 }
737 elsif (defined $current_proto and $current_proto eq 'eventlog') {
738 $syslog_xobj->Close();
89c3c464 739 return 1;
740 }
6e4ef777 741
89c3c464 742 return close SYSLOG;
743}
6e4ef777 744
89c3c464 7451;
942974c1 746
89c3c464 747__END__
5be1dfc7 748
89c3c464 749=head1 NAME
8168e71f 750
89c3c464 751Sys::Syslog - Perl interface to the UNIX syslog(3) calls
3ffabb8c 752
89c3c464 753=head1 VERSION
3ffabb8c 754
d329efa2 755Version 0.21
23642f4b 756
89c3c464 757=head1 SYNOPSIS
cb63fe9d 758
89c3c464 759 use Sys::Syslog; # all except setlogsock(), or:
760 use Sys::Syslog qw(:DEFAULT setlogsock); # default set, plus setlogsock()
761 use Sys::Syslog qw(:standard :macros); # standard functions, plus macros
23642f4b 762
89c3c464 763 openlog $ident, $logopt, $facility; # don't forget this
764 syslog $priority, $format, @args;
765 $oldmask = setlogmask $mask_priority;
766 closelog;
cb63fe9d 767
942974c1 768
89c3c464 769=head1 DESCRIPTION
5be1dfc7 770
89c3c464 771C<Sys::Syslog> is an interface to the UNIX C<syslog(3)> program.
772Call C<syslog()> with a string priority and a list of C<printf()> args
773just like C<syslog(3)>.
5be1dfc7 774
a650b841 775You can find a kind of FAQ in L<"THE RULES OF SYS::SYSLOG">. Please read
776it before coding, and again before asking questions.
777
5be1dfc7 778
89c3c464 779=head1 EXPORTS
5be1dfc7 780
89c3c464 781C<Sys::Syslog> exports the following C<Exporter> tags:
5be1dfc7 782
89c3c464 783=over 4
784
785=item *
786
787C<:standard> exports the standard C<syslog(3)> functions:
788
789 openlog closelog setlogmask syslog
790
791=item *
792
793C<:extended> exports the Perl specific functions for C<syslog(3)>:
794
795 setlogsock
796
797=item *
798
799C<:macros> exports the symbols corresponding to most of your C<syslog(3)>
800macros and the C<LOG_UPTO()> and C<LOG_MASK()> functions.
801See L<"CONSTANTS"> for the supported constants and their meaning.
802
803=back
804
805By default, C<Sys::Syslog> exports the symbols from the C<:standard> tag.
806
807
808=head1 FUNCTIONS
809
810=over 4
811
812=item B<openlog($ident, $logopt, $facility)>
813
814Opens the syslog.
815C<$ident> is prepended to every message. C<$logopt> contains zero or
816more of the options detailed below. C<$facility> specifies the part
817of the system to report about, for example C<LOG_USER> or C<LOG_LOCAL0>:
818see L<"Facilities"> for a list of well-known facilities, and your
819C<syslog(3)> documentation for the facilities available in your system.
820Check L<"SEE ALSO"> for useful links. Facility can be given as a string
821or a numeric macro.
822
823This function will croak if it can't connect to the syslog daemon.
824
825Note that C<openlog()> now takes three arguments, just like C<openlog(3)>.
826
827B<You should use C<openlog()> before calling C<syslog()>.>
828
829B<Options>
830
831=over 4
832
833=item *
834
835C<cons> - This option is ignored, since the failover mechanism will drop
836down to the console automatically if all other media fail.
837
838=item *
839
840C<ndelay> - Open the connection immediately (normally, the connection is
841opened when the first message is logged).
842
843=item *
844
845C<nofatal> - When set to true, C<openlog()> and C<syslog()> will only
846emit warnings instead of dying if the connection to the syslog can't
847be established.
848
849=item *
850
851C<nowait> - Don't wait for child processes that may have been created
852while logging the message. (The GNU C library does not create a child
853process, so this option has no effect on Linux.)
854
855=item *
856
857C<pid> - Include PID with each message.
858
859=back
860
861B<Examples>
862
863Open the syslog with options C<ndelay> and C<pid>, and with facility C<LOCAL0>:
864
865 openlog($name, "ndelay,pid", "local0");
866
867Same thing, but this time using the macro corresponding to C<LOCAL0>:
868
869 openlog($name, "ndelay,pid", LOG_LOCAL0);
870
871
872=item B<syslog($priority, $message)>
873
874=item B<syslog($priority, $format, @args)>
875
876If C<$priority> permits, logs C<$message> or C<sprintf($format, @args)>
877with the addition that C<%m> in $message or C<$format> is replaced with
878C<"$!"> (the latest error message).
879
880C<$priority> can specify a level, or a level and a facility. Levels and
a650b841 881facilities can be given as strings or as macros. When using the C<eventlog>
882mechanism, priorities C<DEBUG> and C<INFO> are mapped to event type
883C<informational>, C<NOTICE> and C<WARNIN> to C<warning> and C<ERR> to
884C<EMERG> to C<error>.
89c3c464 885
886If you didn't use C<openlog()> before using C<syslog()>, C<syslog()> will
887try to guess the C<$ident> by extracting the shortest prefix of
888C<$format> that ends in a C<":">.
889
890B<Examples>
891
892 syslog("info", $message); # informational level
893 syslog(LOG_INFO, $message); # informational level
894
895 syslog("info|local0", $message); # information level, Local0 facility
896 syslog(LOG_INFO|LOG_LOCAL0, $message); # information level, Local0 facility
897
898=over 4
899
900=item B<Note>
901
902C<Sys::Syslog> version v0.07 and older passed the C<$message> as the
903formatting string to C<sprintf()> even when no formatting arguments
904were provided. If the code calling C<syslog()> might execute with
905older versions of this module, make sure to call the function as
906C<syslog($priority, "%s", $message)> instead of C<syslog($priority,
907$message)>. This protects against hostile formatting sequences that
908might show up if $message contains tainted data.
909
910=back
911
912
913=item B<setlogmask($mask_priority)>
914
915Sets the log mask for the current process to C<$mask_priority> and
916returns the old mask. If the mask argument is 0, the current log mask
917is not modified. See L<"Levels"> for the list of available levels.
918You can use the C<LOG_UPTO()> function to allow all levels up to a
919given priority (but it only accept the numeric macros as arguments).
920
921B<Examples>
922
923Only log errors:
924
925 setlogmask( LOG_MASK(LOG_ERR) );
926
927Log everything except informational messages:
928
929 setlogmask( ~(LOG_MASK(LOG_INFO)) );
930
931Log critical messages, errors and warnings:
932
933 setlogmask( LOG_MASK(LOG_CRIT) | LOG_MASK(LOG_ERR) | LOG_MASK(LOG_WARNING) );
934
935Log all messages up to debug:
936
937 setlogmask( LOG_UPTO(LOG_DEBUG) );
938
939
940=item B<setlogsock($sock_type)>
941
07b7e4bc 942=item B<setlogsock($sock_type, $stream_location)> (added in Perl 5.004_02)
89c3c464 943
944Sets the socket type to be used for the next call to
945C<openlog()> or C<syslog()> and returns true on success,
4b035b3d 946C<undef> on failure. The available mechanisms are:
947
948=over
949
950=item *
951
07b7e4bc 952C<"native"> - use the native C functions from your C<syslog(3)> library
953(added in C<Sys::Syslog> 0.15).
4b035b3d 954
955=item *
956
d329efa2 957C<"eventlog"> - send messages to the Win32 events logger (Win32 only;
958added in C<Sys::Syslog> 0.19).
959
960=item *
961
4b035b3d 962C<"tcp"> - connect to a TCP socket, on the C<syslog/tcp> or C<syslogng/tcp>
963service.
964
965=item *
966
967C<"udp"> - connect to a UDP socket, on the C<syslog/udp> service.
968
969=item *
970
971C<"inet"> - connect to an INET socket, either TCP or UDP, tried in that order.
972
973=item *
974
975C<"unix"> - connect to a UNIX domain socket (in some systems a character
976special device). The name of that socket is the second parameter or, if
977you omit the second parameter, the value returned by the C<_PATH_LOG> macro
978(if your system defines it), or F</dev/log> or F</dev/conslog>, whatever is
979writable.
980
981=item *
982
983C<"stream"> - connect to the stream indicated by the pathname provided as
984the optional second parameter, or, if omitted, to F</dev/conslog>.
985For example Solaris and IRIX system may prefer C<"stream"> instead of C<"unix">.
986
987=item *
988
d329efa2 989C<"pipe"> - connect to the named pipe indicated by the pathname provided as
990the optional second parameter, or, if omitted, to the value returned by
991the C<_PATH_LOG> macro (if your system defines it), or F</dev/log>
992(added in C<Sys::Syslog> 0.21).
4b035b3d 993
a650b841 994=item *
995
d329efa2 996C<"console"> - send messages directly to the console, as for the C<"cons">
997option of C<openlog()>.
a650b841 998
4b035b3d 999=back
89c3c464 1000
1001A reference to an array can also be passed as the first parameter.
1002When this calling method is used, the array should contain a list of
4b035b3d 1003mechanisms which are attempted in order.
89c3c464 1004
4b035b3d 1005The default is to try C<native>, C<tcp>, C<udp>, C<unix>, C<stream>, C<console>.
d329efa2 1006Under Win32 systems, C<eventlog> will be added as the first mechanism to try
1007if C<Win32::EventLog> is available.
89c3c464 1008
07b7e4bc 1009Giving an invalid value for C<$sock_type> will C<croak>.
89c3c464 1010
4b035b3d 1011B<Examples>
1012
1013Select the UDP socket mechanism:
1014
1015 setlogsock("udp");
1016
1017Select the native, UDP socket then UNIX domain socket mechanisms:
1018
1019 setlogsock(["native", "udp", "unix"]);
1020
07b7e4bc 1021=over
1022
1023=item B<Note>
1024
1025Now that the "native" mechanism is supported by C<Sys::Syslog> and selected
1026by default, the use of the C<setlogsock()> function is discouraged because
1027other mechanisms are less portable across operating systems. Authors of
1028modules and programs that use this function, especially its cargo-cult form
1029C<setlogsock("unix")>, are advised to remove any occurence of it unless they
1030specifically want to use a given mechanism (like TCP or UDP to connect to
1031a remote host).
1032
1033=back
89c3c464 1034
1035=item B<closelog()>
1036
4b035b3d 1037Closes the log file and returns true on success.
89c3c464 1038
1039=back
1040
1041
a650b841 1042=head1 THE RULES OF SYS::SYSLOG
1043
1044I<The First Rule of Sys::Syslog is:>
1045You do not call C<setlogsock>.
1046
1047I<The Second Rule of Sys::Syslog is:>
1048You B<do not> call C<setlogsock>.
1049
1050I<The Third Rule of Sys::Syslog is:>
1051The program crashes, C<die>s, calls C<closelog>, the log is over.
1052
1053I<The Fourth Rule of Sys::Syslog is:>
1054One facility, one priority.
1055
1056I<The Fifth Rule of Sys::Syslog is:>
1057One log at a time.
1058
1059I<The Sixth Rule of Sys::Syslog is:>
1060No C<syslog> before C<openlog>.
1061
1062I<The Seventh Rule of Sys::Syslog is:>
1063Logs will go on as long as they have to.
1064
1065I<The Eighth, and Final Rule of Sys::Syslog is:>
1066If this is your first use of Sys::Syslog, you must read the doc.
1067
1068
89c3c464 1069=head1 EXAMPLES
1070
a650b841 1071An example:
1072
89c3c464 1073 openlog($program, 'cons,pid', 'user');
1074 syslog('info', '%s', 'this is another test');
1075 syslog('mail|warning', 'this is a better test: %d', time);
1076 closelog();
5be1dfc7 1077
1078 syslog('debug', 'this is the last test');
cb63fe9d 1079
a650b841 1080Another example:
1081
5be1dfc7 1082 openlog("$program $$", 'ndelay', 'user');
1083 syslog('notice', 'fooprogram: this is really done');
1084
a650b841 1085Example of use of C<%m>:
1086
5be1dfc7 1087 $! = 55;
6e4ef777 1088 syslog('info', 'problem was %m'); # %m == $! in syslog(3)
1089
1090Log to UDP port on C<$remotehost> instead of logging locally:
5be1dfc7 1091
476b65d9 1092 setlogsock('udp');
1093 $Sys::Syslog::host = $remotehost;
1094 openlog($program, 'ndelay', 'user');
1095 syslog('info', 'something happened over here');
1096
8168e71f 1097
1098=head1 CONSTANTS
1099
1100=head2 Facilities
1101
1102=over 4
1103
1104=item *
1105
a650b841 1106C<LOG_AUDIT> - audit daemon (IRIX); falls back to C<LOG_AUTH>
1107
1108=item *
1109
8168e71f 1110C<LOG_AUTH> - security/authorization messages
1111
1112=item *
1113
1114C<LOG_AUTHPRIV> - security/authorization messages (private)
1115
1116=item *
1117
a650b841 1118C<LOG_CONSOLE> - C</dev/console> output (FreeBSD); falls back to C<LOG_USER>
1119
1120=item *
1121
4b035b3d 1122C<LOG_CRON> - clock daemons (B<cron> and B<at>)
8168e71f 1123
1124=item *
1125
1126C<LOG_DAEMON> - system daemons without separate facility value
1127
1128=item *
1129
4b035b3d 1130C<LOG_FTP> - FTP daemon
8168e71f 1131
1132=item *
1133
1134C<LOG_KERN> - kernel messages
1135
1136=item *
1137
a650b841 1138C<LOG_INSTALL> - installer subsystem (Mac OS X); falls back to C<LOG_USER>
4b035b3d 1139
1140=item *
1141
a650b841 1142C<LOG_LAUNCHD> - launchd - general bootstrap daemon (Mac OS X);
1143falls back to C<LOG_DAEMON>
1144
1145=item *
1146
1147C<LOG_LFMT> - logalert facility; falls back to C<LOG_USER>
4b035b3d 1148
1149=item *
1150
8168e71f 1151C<LOG_LOCAL0> through C<LOG_LOCAL7> - reserved for local use
1152
1153=item *
1154
1155C<LOG_LPR> - line printer subsystem
1156
1157=item *
1158
1159C<LOG_MAIL> - mail subsystem
1160
1161=item *
1162
a650b841 1163C<LOG_NETINFO> - NetInfo subsystem (Mac OS X); falls back to C<LOG_DAEMON>
4b035b3d 1164
1165=item *
1166
8168e71f 1167C<LOG_NEWS> - USENET news subsystem
1168
1169=item *
1170
a650b841 1171C<LOG_NTP> - NTP subsystem (FreeBSD, NetBSD); falls back to C<LOG_DAEMON>
1172
1173=item *
1174
1175C<LOG_RAS> - Remote Access Service (VPN / PPP) (Mac OS X);
1176falls back to C<LOG_AUTH>
4b035b3d 1177
1178=item *
1179
a650b841 1180C<LOG_REMOTEAUTH> - remote authentication/authorization (Mac OS X);
1181falls back to C<LOG_AUTH>
1182
1183=item *
1184
1185C<LOG_SECURITY> - security subsystems (firewalling, etc.) (FreeBSD);
1186falls back to C<LOG_AUTH>
4b035b3d 1187
1188=item *
1189
8168e71f 1190C<LOG_SYSLOG> - messages generated internally by B<syslogd>
1191
1192=item *
1193
1194C<LOG_USER> (default) - generic user-level messages
1195
1196=item *
1197
1198C<LOG_UUCP> - UUCP subsystem
1199
1200=back
1201
1202
1203=head2 Levels
1204
1205=over 4
1206
1207=item *
1208
1209C<LOG_EMERG> - system is unusable
1210
1211=item *
1212
1213C<LOG_ALERT> - action must be taken immediately
1214
1215=item *
1216
1217C<LOG_CRIT> - critical conditions
1218
1219=item *
1220
942974c1 1221C<LOG_ERR> - error conditions
8168e71f 1222
1223=item *
1224
1225C<LOG_WARNING> - warning conditions
1226
1227=item *
1228
1229C<LOG_NOTICE> - normal, but significant, condition
1230
1231=item *
1232
1233C<LOG_INFO> - informational message
1234
1235=item *
1236
1237C<LOG_DEBUG> - debug-level message
1238
1239=back
1240
1241
1242=head1 DIAGNOSTICS
1243
a650b841 1244=over
8168e71f 1245
a650b841 1246=item C<Invalid argument passed to setlogsock>
8168e71f 1247
1248B<(F)> You gave C<setlogsock()> an invalid value for C<$sock_type>.
1249
a650b841 1250=item C<eventlog passed to setlogsock, but operating system isn't Win32-compatible>
1251
1252B<(W)> You asked C<setlogsock()> to use the Win32 event logger but the
1253operating system running the program isn't Win32 or does not provides Win32
1254facilities.
1255
1256=item C<no connection to syslog available>
8168e71f 1257
1258B<(F)> C<syslog()> failed to connect to the specified socket.
1259
a650b841 1260=item C<stream passed to setlogsock, but %s is not writable>
8168e71f 1261
942974c1 1262B<(W)> You asked C<setlogsock()> to use a stream socket, but the given
8168e71f 1263path is not writable.
1264
a650b841 1265=item C<stream passed to setlogsock, but could not find any device>
8168e71f 1266
942974c1 1267B<(W)> You asked C<setlogsock()> to use a stream socket, but didn't
8168e71f 1268provide a path, and C<Sys::Syslog> was unable to find an appropriate one.
1269
a650b841 1270=item C<tcp passed to setlogsock, but tcp service unavailable>
8168e71f 1271
942974c1 1272B<(W)> You asked C<setlogsock()> to use a TCP socket, but the service
8168e71f 1273is not available on the system.
1274
a650b841 1275=item C<syslog: expecting argument %s>
8168e71f 1276
1277B<(F)> You forgot to give C<syslog()> the indicated argument.
1278
a650b841 1279=item C<syslog: invalid level/facility: %s>
8168e71f 1280
6e4ef777 1281B<(F)> You specified an invalid level or facility.
8168e71f 1282
a650b841 1283=item C<syslog: too many levels given: %s>
8168e71f 1284
1285B<(F)> You specified too many levels.
1286
a650b841 1287=item C<syslog: too many facilities given: %s>
8168e71f 1288
1289B<(F)> You specified too many facilities.
1290
a650b841 1291=item C<syslog: level must be given>
8168e71f 1292
1293B<(F)> You forgot to specify a level.
1294
a650b841 1295=item C<udp passed to setlogsock, but udp service unavailable>
8168e71f 1296
942974c1 1297B<(W)> You asked C<setlogsock()> to use a UDP socket, but the service
8168e71f 1298is not available on the system.
1299
a650b841 1300=item C<unix passed to setlogsock, but path not available>
8168e71f 1301
942974c1 1302B<(W)> You asked C<setlogsock()> to use a UNIX socket, but C<Sys::Syslog>
8168e71f 1303was unable to find an appropriate an appropriate device.
1304
1305=back
1306
1307
5be1dfc7 1308=head1 SEE ALSO
1309
a650b841 1310=head2 Manual Pages
1311
5be1dfc7 1312L<syslog(3)>
1313
6e4ef777 1314SUSv3 issue 6, IEEE Std 1003.1, 2004 edition,
1315L<http://www.opengroup.org/onlinepubs/000095399/basedefs/syslog.h.html>
1316
1317GNU C Library documentation on syslog,
1318L<http://www.gnu.org/software/libc/manual/html_node/Syslog.html>
1319
1320Solaris 10 documentation on syslog,
1321L<http://docs.sun.com/app/docs/doc/816-5168/6mbb3hruo?a=view>
1322
a650b841 1323IRIX 6.4 documentation on syslog,
1324L<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0640&db=man&fname=3c+syslog>
1325
6e4ef777 1326AIX 5L 5.3 documentation on syslog,
d329efa2 1327L<http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf2/syslog.htm>
6e4ef777 1328
1329HP-UX 11i documentation on syslog,
1330L<http://docs.hp.com/en/B9106-90010/syslog.3C.html>
1331
1332Tru64 5.1 documentation on syslog,
1333L<http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51_HTML/MAN/MAN3/0193____.HTM>
1334
1335Stratus VOS 15.1,
1336L<http://stratadoc.stratus.com/vos/15.1.1/r502-01/wwhelp/wwhimpl/js/html/wwhelp.htm?context=r502-01&file=ch5r502-01bi.html>
1337
a650b841 1338=head2 RFCs
1339
6e4ef777 1340I<RFC 3164 - The BSD syslog Protocol>, L<http://www.faqs.org/rfcs/rfc3164.html>
1341-- Please note that this is an informational RFC, and therefore does not
1342specify a standard of any kind.
1343
1344I<RFC 3195 - Reliable Delivery for syslog>, L<http://www.faqs.org/rfcs/rfc3195.html>
1345
a650b841 1346=head2 Articles
1347
04f98b29 1348I<Syslogging with Perl>, L<http://lexington.pm.org/meetings/022001.html>
1349
a650b841 1350=head2 Event Log
8168e71f 1351
a650b841 1352Windows Event Log,
1353L<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wes/wes/windows_event_log.asp>
5be1dfc7 1354
a650b841 1355
1356=head1 AUTHORS & ACKNOWLEDGEMENTS
1357
1358Tom Christiansen E<lt>F<tchrist (at) perl.com>E<gt> and Larry Wall
1359E<lt>F<larry (at) wall.org>E<gt>.
150b260b 1360
1361UNIX domain sockets added by Sean Robinson
a650b841 1362E<lt>F<robinson_s (at) sc.maricopa.edu>E<gt> with support from Tim Bunce
1363E<lt>F<Tim.Bunce (at) ig.co.uk>E<gt> and the C<perl5-porters> mailing list.
150b260b 1364
1365Dependency on F<syslog.ph> replaced with XS code by Tom Hughes
a650b841 1366E<lt>F<tom (at) compton.nu>E<gt>.
5be1dfc7 1367
a650b841 1368Code for C<constant()>s regenerated by Nicholas Clark E<lt>F<nick (at) ccl4.org>E<gt>.
23642f4b 1369
1370Failover to different communication modes by Nick Williams
a650b841 1371E<lt>F<Nick.Williams (at) morganstanley.com>E<gt>.
1372
1373Extracted from core distribution for publishing on the CPAN by
1374SE<eacute>bastien Aperghis-Tramoni E<lt>sebastien (at) aperghis.netE<gt>.
b903fcff 1375
89c3c464 1376XS code for using native C functions borrowed from C<L<Unix::Syslog>>,
a650b841 1377written by Marcus Harnisch E<lt>F<marcus.harnisch (at) gmx.net>E<gt>.
89c3c464 1378
a650b841 1379Yves Orton suggested and helped for making C<Sys::Syslog> use the native
1380event logger under Win32 systems.
1381
1382Jerry D. Hedden and Reini Urban provided greatly appreciated help to
1383debug and polish C<Sys::Syslog> under Cygwin.
8168e71f 1384
1385
1386=head1 BUGS
1387
1388Please report any bugs or feature requests to
a650b841 1389C<bug-sys-syslog (at) rt.cpan.org>, or through the web interface at
8168e71f 1390L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Syslog>.
1391I will be notified, and then you'll automatically be notified of progress on
1392your bug as I make changes.
1393
1394
1395=head1 SUPPORT
1396
1397You can find documentation for this module with the perldoc command.
1398
1399 perldoc Sys::Syslog
1400
1401You can also look for information at:
1402
1403=over 4
1404
1405=item * AnnoCPAN: Annotated CPAN documentation
1406
1407L<http://annocpan.org/dist/Sys-Syslog>
1408
1409=item * CPAN Ratings
1410
1411L<http://cpanratings.perl.org/d/Sys-Syslog>
1412
1413=item * RT: CPAN's request tracker
1414
1415L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Syslog>
1416
1417=item * Search CPAN
1418
6e4ef777 1419L<http://search.cpan.org/dist/Sys-Syslog/>
1420
1421=item * Kobes' CPAN Search
1422
1423L<http://cpan.uwinnipeg.ca/dist/Sys-Syslog>
1424
1425=item * Perl Documentation
1426
1427L<http://perldoc.perl.org/Sys/Syslog.html>
8168e71f 1428
1429=back
1430
1431
1432=head1 LICENSE
1433
1434This program is free software; you can redistribute it and/or modify it
1435under the same terms as Perl itself.
1436
5be1dfc7 1437=cut
a650b841 1438
1439=begin comment
1440
1441Notes for the future maintainer (even if it's still me..)
1442- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1443
1444Using Google Code Search, I search who on Earth was relying on $host being
1445public. It found 5 hits:
1446
1447* First was inside Indigo Star Perl2exe documentation. Just an old version
1448of Sys::Syslog.
1449
1450
1451* One real hit was inside DalWeathDB, a weather related program. It simply
1452does a
1453
1454 $Sys::Syslog::host = '127.0.0.1';
1455
1456- L<http://www.gallistel.net/nparker/weather/code/>
1457
1458
1459* Two hits were in TPC, a fax server thingy. It does a
1460
1461 $Sys::Syslog::host = $TPC::LOGHOST;
1462
1463but also has this strange piece of code:
1464
1465 # work around perl5.003 bug
1466 sub Sys::Syslog::hostname {}
1467
1468I don't know what bug the author referred to.
1469
1470- L<http://www.tpc.int/>
1471- L<ftp://ftp.tpc.int/tpc/server/UNIX/>
1472- L<ftp://ftp-usa.tpc.int/pub/tpc/server/UNIX/>
1473
1474
1475* Last hit was in Filefix, which seems to be a FIDOnet mail program (!).
1476This one does not use $host, but has the following piece of code:
1477
1478 sub Sys::Syslog::hostname
1479 {
1480 use Sys::Hostname;
1481 return hostname;
1482 }
1483
1484I guess this was a more elaborate form of the previous bit, maybe because
1485of a bug in Sys::Syslog back then?
1486
1487- L<ftp://ftp.kiae.su/pub/unix/fido/>
1488
d329efa2 1489
1490Links
1491-----
1492II12021: SYSLOGD HOWTO TCPIPINFO (z/OS, OS/390, MVS)
1493- L<http://www-1.ibm.com/support/docview.wss?uid=isg1II12021>
1494
1495Getting the most out of the Event Viewer
1496- L<http://www.codeproject.com/dotnet/evtvwr.asp?print=true>
1497
1498Log events to the Windows NT Event Log with JNI
1499- L<http://www.javaworld.com/javaworld/jw-09-2001/jw-0928-ntmessages.html>
1500
a650b841 1501=end comment
d329efa2 1502