source: trunk/essentials/dev-lang/perl/lib/syslog.pl

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 4.7 KB
Line 
1#
2# syslog.pl
3#
4# $Log: syslog.pl,v $
5#
6# tom christiansen <[email protected]>
7# modified to use sockets by Larry Wall <[email protected]>
8# NOTE: openlog now takes three arguments, just like openlog(3)
9#
10# call syslog() with a string priority and a list of printf() args
11# like syslog(3)
12#
13# usage: require 'syslog.pl';
14#
15# then (put these all in a script to test function)
16#
17#
18# do openlog($program,'cons,pid','user');
19# do syslog('info','this is another test');
20# do syslog('mail|warning','this is a better test: %d', time);
21# do closelog();
22#
23# do syslog('debug','this is the last test');
24# do openlog("$program $$",'ndelay','user');
25# do syslog('notice','fooprogram: this is really done');
26#
27# $! = 55;
28# do syslog('info','problem was %m'); # %m == $! in syslog(3)
29
30package syslog;
31
32use warnings::register;
33
34$host = 'localhost' unless $host; # set $syslog'host to change
35
36if ($] >= 5 && warnings::enabled()) {
37 warnings::warn("You should 'use Sys::Syslog' instead; continuing");
38}
39
40require 'syslog.ph';
41
42 eval 'use Socket; 1' ||
43 eval { require "socket.ph" } ||
44 require "sys/socket.ph";
45
46$maskpri = &LOG_UPTO(&LOG_DEBUG);
47
48sub main'openlog {
49 ($ident, $logopt, $facility) = @_; # package vars
50 $lo_pid = $logopt =~ /\bpid\b/;
51 $lo_ndelay = $logopt =~ /\bndelay\b/;
52 $lo_cons = $logopt =~ /\bcons\b/;
53 $lo_nowait = $logopt =~ /\bnowait\b/;
54 &connect if $lo_ndelay;
55}
56
57sub main'closelog {
58 $facility = $ident = '';
59 &disconnect;
60}
61
62sub main'setlogmask {
63 local($oldmask) = $maskpri;
64 $maskpri = shift;
65 $oldmask;
66}