📄 syslog.pm
字号:
=backA reference to an array can also be passed as the first parameter.When this calling method is used, the array should contain a list ofmechanisms which are attempted in order.The default is to try C<native>, C<tcp>, C<udp>, C<unix>, C<stream>, C<console>.Under systems with the Win32 API, C<eventlog> will be added as the first mechanism to try if C<Win32::EventLog> is available.Giving an invalid value for C<$sock_type> will C<croak>.B<Examples>Select the UDP socket mechanism: setlogsock("udp");Select the native, UDP socket then UNIX domain socket mechanisms: setlogsock(["native", "udp", "unix"]);=over=item B<Note>Now that the "native" mechanism is supported by C<Sys::Syslog> and selected by default, the use of the C<setlogsock()> function is discouraged because other mechanisms are less portable across operating systems. Authors of modules and programs that use this function, especially its cargo-cult form C<setlogsock("unix")>, are advised to remove any occurence of it unless they specifically want to use a given mechanism (like TCP or UDP to connect to a remote host).=back=item B<closelog()>Closes the log file and returns true on success.=back=head1 THE RULES OF SYS::SYSLOGI<The First Rule of Sys::Syslog is:>You do not call C<setlogsock>.I<The Second Rule of Sys::Syslog is:>You B<do not> call C<setlogsock>.I<The Third Rule of Sys::Syslog is:>The program crashes, C<die>s, calls C<closelog>, the log is over.I<The Fourth Rule of Sys::Syslog is:>One facility, one priority.I<The Fifth Rule of Sys::Syslog is:>One log at a time.I<The Sixth Rule of Sys::Syslog is:>No C<syslog> before C<openlog>.I<The Seventh Rule of Sys::Syslog is:>Logs will go on as long as they have to. I<The Eighth, and Final Rule of Sys::Syslog is:>If this is your first use of Sys::Syslog, you must read the doc.=head1 EXAMPLESAn example: openlog($program, 'cons,pid', 'user'); syslog('info', '%s', 'this is another test'); syslog('mail|warning', 'this is a better test: %d', time); closelog(); syslog('debug', 'this is the last test');Another example: openlog("$program $$", 'ndelay', 'user'); syslog('notice', 'fooprogram: this is really done');Example of use of C<%m>: $! = 55; syslog('info', 'problem was %m'); # %m == $! in syslog(3)Log to UDP port on C<$remotehost> instead of logging locally: setlogsock('udp'); $Sys::Syslog::host = $remotehost; openlog($program, 'ndelay', 'user'); syslog('info', 'something happened over here');=head1 CONSTANTS=head2 Facilities=over 4=item *C<LOG_AUDIT> - audit daemon (IRIX); falls back to C<LOG_AUTH>=item *C<LOG_AUTH> - security/authorization messages=item *C<LOG_AUTHPRIV> - security/authorization messages (private)=item *C<LOG_CONSOLE> - C</dev/console> output (FreeBSD); falls back to C<LOG_USER>=item *C<LOG_CRON> - clock daemons (B<cron> and B<at>)=item *C<LOG_DAEMON> - system daemons without separate facility value=item *C<LOG_FTP> - FTP daemon=item *C<LOG_KERN> - kernel messages=item *C<LOG_INSTALL> - installer subsystem (Mac OS X); falls back to C<LOG_USER>=item *C<LOG_LAUNCHD> - launchd - general bootstrap daemon (Mac OS X);falls back to C<LOG_DAEMON>=item *C<LOG_LFMT> - logalert facility; falls back to C<LOG_USER>=item *C<LOG_LOCAL0> through C<LOG_LOCAL7> - reserved for local use=item *C<LOG_LPR> - line printer subsystem=item *C<LOG_MAIL> - mail subsystem=item *C<LOG_NETINFO> - NetInfo subsystem (Mac OS X); falls back to C<LOG_DAEMON>=item *C<LOG_NEWS> - USENET news subsystem=item *C<LOG_NTP> - NTP subsystem (FreeBSD, NetBSD); falls back to C<LOG_DAEMON>=item *C<LOG_RAS> - Remote Access Service (VPN / PPP) (Mac OS X);falls back to C<LOG_AUTH>=item *C<LOG_REMOTEAUTH> - remote authentication/authorization (Mac OS X);falls back to C<LOG_AUTH>=item *C<LOG_SECURITY> - security subsystems (firewalling, etc.) (FreeBSD);falls back to C<LOG_AUTH>=item *C<LOG_SYSLOG> - messages generated internally by B<syslogd>=item *C<LOG_USER> (default) - generic user-level messages=item *C<LOG_UUCP> - UUCP subsystem=back=head2 Levels=over 4=item *C<LOG_EMERG> - system is unusable=item *C<LOG_ALERT> - action must be taken immediately=item *C<LOG_CRIT> - critical conditions=item *C<LOG_ERR> - error conditions=item *C<LOG_WARNING> - warning conditions=item *C<LOG_NOTICE> - normal, but significant, condition=item *C<LOG_INFO> - informational message=item *C<LOG_DEBUG> - debug-level message=back=head1 DIAGNOSTICS=over=item C<Invalid argument passed to setlogsock>B<(F)> You gave C<setlogsock()> an invalid value for C<$sock_type>. =item C<eventlog passed to setlogsock, but no Win32 API available>B<(W)> You asked C<setlogsock()> to use the Win32 event logger but the operating system running the program isn't Win32 or does not provides Win32compatible facilities.=item C<no connection to syslog available>B<(F)> C<syslog()> failed to connect to the specified socket.=item C<stream passed to setlogsock, but %s is not writable>B<(W)> You asked C<setlogsock()> to use a stream socket, but the given path is not writable. =item C<stream passed to setlogsock, but could not find any device>B<(W)> You asked C<setlogsock()> to use a stream socket, but didn't provide a path, and C<Sys::Syslog> was unable to find an appropriate one.=item C<tcp passed to setlogsock, but tcp service unavailable>B<(W)> You asked C<setlogsock()> to use a TCP socket, but the service is not available on the system. =item C<syslog: expecting argument %s>B<(F)> You forgot to give C<syslog()> the indicated argument.=item C<syslog: invalid level/facility: %s>B<(F)> You specified an invalid level or facility.=item C<syslog: too many levels given: %s>B<(F)> You specified too many levels. =item C<syslog: too many facilities given: %s>B<(F)> You specified too many facilities. =item C<syslog: level must be given>B<(F)> You forgot to specify a level.=item C<udp passed to setlogsock, but udp service unavailable>B<(W)> You asked C<setlogsock()> to use a UDP socket, but the service is not available on the system. =item C<unix passed to setlogsock, but path not available>B<(W)> You asked C<setlogsock()> to use a UNIX socket, but C<Sys::Syslog> was unable to find an appropriate an appropriate device.=back=head1 SEE ALSO=head2 Manual PagesL<syslog(3)>SUSv3 issue 6, IEEE Std 1003.1, 2004 edition, L<http://www.opengroup.org/onlinepubs/000095399/basedefs/syslog.h.html>GNU C Library documentation on syslog, L<http://www.gnu.org/software/libc/manual/html_node/Syslog.html>Solaris 10 documentation on syslog, L<http://docs.sun.com/app/docs/doc/816-5168/6mbb3hruo?a=view>IRIX 6.4 documentation on syslog,L<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0640&db=man&fname=3c+syslog>AIX 5L 5.3 documentation on syslog, L<http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf2/syslog.htm>HP-UX 11i documentation on syslog, L<http://docs.hp.com/en/B9106-90010/syslog.3C.html>Tru64 5.1 documentation on syslog, L<http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51_HTML/MAN/MAN3/0193____.HTM>Stratus VOS 15.1, L<http://stratadoc.stratus.com/vos/15.1.1/r502-01/wwhelp/wwhimpl/js/html/wwhelp.htm?context=r502-01&file=ch5r502-01bi.html>=head2 RFCsI<RFC 3164 - The BSD syslog Protocol>, L<http://www.faqs.org/rfcs/rfc3164.html>-- Please note that this is an informational RFC, and therefore does not specify a standard of any kind.I<RFC 3195 - Reliable Delivery for syslog>, L<http://www.faqs.org/rfcs/rfc3195.html>=head2 ArticlesI<Syslogging with Perl>, L<http://lexington.pm.org/meetings/022001.html>=head2 Event LogWindows Event Log,L<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wes/wes/windows_event_log.asp>=head1 AUTHORS & ACKNOWLEDGEMENTSTom Christiansen E<lt>F<tchrist (at) perl.com>E<gt> and Larry WallE<lt>F<larry (at) wall.org>E<gt>.UNIX domain sockets added by Sean RobinsonE<lt>F<robinson_s (at) sc.maricopa.edu>E<gt> with support from Tim Bunce E<lt>F<Tim.Bunce (at) ig.co.uk>E<gt> and the C<perl5-porters> mailing list.Dependency on F<syslog.ph> replaced with XS code by Tom HughesE<lt>F<tom (at) compton.nu>E<gt>.Code for C<constant()>s regenerated by Nicholas Clark E<lt>F<nick (at) ccl4.org>E<gt>.Failover to different communication modes by Nick WilliamsE<lt>F<Nick.Williams (at) morganstanley.com>E<gt>.Extracted from core distribution for publishing on the CPAN by SE<eacute>bastien Aperghis-Tramoni E<lt>sebastien (at) aperghis.netE<gt>.XS code for using native C functions borrowed from C<L<Unix::Syslog>>, written by Marcus Harnisch E<lt>F<marcus.harnisch (at) gmx.net>E<gt>.Yves Orton suggested and helped for making C<Sys::Syslog> use the native event logger under Win32 systems.Jerry D. Hedden and Reini Urban provided greatly appreciated help to debug and polish C<Sys::Syslog> under Cygwin.=head1 BUGSPlease report any bugs or feature requests toC<bug-sys-syslog (at) rt.cpan.org>, or through the web interface atL<http://rt.cpan.org/Public/Dist/Display.html?Name=Sys-Syslog>.I will be notified, and then you'll automatically be notified of progress onyour bug as I make changes.=head1 SUPPORTYou can find documentation for this module with the perldoc command. perldoc Sys::SyslogYou can also look for information at:=over 4=item * AnnoCPAN: Annotated CPAN documentationL<http://annocpan.org/dist/Sys-Syslog>=item * CPAN RatingsL<http://cpanratings.perl.org/d/Sys-Syslog>=item * RT: CPAN's request trackerL<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Syslog>=item * Search CPANL<http://search.cpan.org/dist/Sys-Syslog/>=item * Kobes' CPAN SearchL<http://cpan.uwinnipeg.ca/dist/Sys-Syslog>=item * Perl DocumentationL<http://perldoc.perl.org/Sys/Syslog.html>=back=head1 COPYRIGHTCopyright (C) 1990-2007 by Larry Wall and others.=head1 LICENSEThis program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.=cut=begin commentNotes for the future maintainer (even if it's still me..)- - - - - - - - - - - - - - - - - - - - - - - - - - - - -Using Google Code Search, I search who on Earth was relying on $host being public. It found 5 hits: * First was inside Indigo Star Perl2exe documentation. Just an old version of Sys::Syslog. * One real hit was inside DalWeathDB, a weather related program. It simply does a $Sys::Syslog::host = '127.0.0.1';- L<http://www.gallistel.net/nparker/weather/code/>* Two hits were in TPC, a fax server thingy. It does a $Sys::Syslog::host = $TPC::LOGHOST;but also has this strange piece of code: # work around perl5.003 bug sub Sys::Syslog::hostname {}I don't know what bug the author referred to.- L<http://www.tpc.int/>- L<ftp://ftp.tpc.int/tpc/server/UNIX/>- L<ftp://ftp-usa.tpc.int/pub/tpc/server/UNIX/>* Last hit was in Filefix, which seems to be a FIDOnet mail program (!).This one does not use $host, but has the following piece of code: sub Sys::Syslog::hostname { use Sys::Hostname; return hostname; }I guess this was a more elaborate form of the previous bit, maybe because of a bug in Sys::Syslog back then?- L<ftp://ftp.kiae.su/pub/unix/fido/>Links-----II12021: SYSLOGD HOWTO TCPIPINFO (z/OS, OS/390, MVS)- L<http://www-1.ibm.com/support/docview.wss?uid=isg1II12021>Getting the most out of the Event Viewer- L<http://www.codeproject.com/dotnet/evtvwr.asp?print=true>Log events to the Windows NT Event Log with JNI- L<http://www.javaworld.com/javaworld/jw-09-2001/jw-0928-ntmessages.html>=end comment
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -