📄 ch32_41.htm
字号:
<html><head><title>Sys::Syslog (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly & Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Sys::Syslog"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch32_40.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch32_01.htm">Chapter 32: Standard Modules</a></td><td align="right" valign="top" width="172"><a href="ch32_42.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">32.41. Sys::Syslog</h2><p><blockquote><pre class="programlisting">use Sys::Syslog; # Misses setlogsock.use Sys::Syslog qw(:DEFAULT setlogsock); # Also gets setlogsock.openlog($program, 'cons,pid', 'user');syslog('info', 'this is another test');syslog('mail|warning', 'this is a better test: %d', time());closelog();syslog('debug', 'this is the last test');setlogsock('unix');openlog("$program $$", 'ndelay', 'user');syslog('info', 'problem was %m'); # %m == $! in syslogesesyslog('notice', 'fooprogram: this is really done');setlogsock("unix"); # "inet" or "unix"openlog("myprogname", $logopt, $facility);syslog($priority, $format, @args);$oldmask = setlogmask($mask_priority);closelog();</pre></blockquote>The <tt class="literal">Sys::Syslog</tt> module acts like your C library's <em class="emphasis">syslog</em>(3)function, sending messages to your system log daemon, <em class="emphasis">syslogd</em>(8).It is especially useful in daemons and other programs lacking aterminal to receive diagnostic output, or for security-mindedprograms that want to produce a more lasting record of their actions(or someone else's actions). Supported functions are:</p><dl><dt><b><tt class="literal">openlog</tt> <em class="replaceable">IDENT</em><tt class="literal">,</tt> <em class="replaceable">OPTLIST</em><tt class="literal">,</tt> <em class="replaceable">FACILITY</em></b></dt><dd><p>Establishes a connection with your friendly syslog daemon. <em class="replaceable">IDENT</em>is the string to log messages under (like <tt class="literal">$0</tt>, your programname). <em class="replaceable">OPTLIST</em> is a string with comma-separated options suchas <tt class="literal">"cons"</tt>, <tt class="literal">"pid"</tt>, and <tt class="literal">"ndelay"</tt>. <em class="replaceable">FACILITY</em> is somethinglike "<tt class="literal">auth</tt>", "<tt class="literal">daemon</tt>", "<tt class="literal">kern</tt>", "<tt class="literal">lpr</tt>", "<tt class="literal">mail</tt>", "<tt class="literal">news</tt>"or "<tt class="literal">user</tt>" for system programs, and one of "<tt class="literal">local0</tt>" <tt class="literal">..</tt>"<tt class="literal">local7</tt>" for local ones. Further messages are logged using thegiven facility and identifying string.</p></dd><dt><b><tt class="literal">syslog</tt> <em class="replaceable">PRIORITY</em><tt class="literal">,</tt> <em class="replaceable">FORMAT</em><tt class="literal">,</tt> <em class="replaceable">ARGS</em></b></dt><dd><p>Sends a message to the daemon using the given <em class="replaceable">PRIORITY</em>. The<em class="replaceable">FORMAT</em> is just like <tt class="literal">printf</tt>--filling in percent escapes using the following <em class="replaceable">ARGS</em>--except that following the conventions of thestandard <em class="emphasis">syslog</em>(3) library function, the special escape "<tt class="literal">%m</tt>"interpolates <tt class="literal">errno</tt> (Perl's <tt class="literal">$!</tt> variable) at that point.</p></dd><dt><b><tt class="literal">setlogsock</tt> <em class="replaceable">TYPE</em></b></dt><dd><p><em class="replaceable">TYPE</em> must be either "<tt class="literal">inet</tt>" or "<tt class="literal">unix</tt>". Some systems' daemonsdo not by default pay attention to incoming Internet-domain syslogmessages, so you might set this to "<tt class="literal">unix</tt>" instead, since it's notthe default.</p></dd><dt><b><tt class="literal">closelog</tt></b></dt><dd><p>Severs the connection with the daemon.</p></dd></dl><p></p><p>For this module to work prior to the 5.6.0 release of Perl, yoursysadmin had to run <em class="emphasis">h2ph</em>(1) on your <em class="emphasis">sys/syslog.h</em> includefile to create a <em class="emphasis">sys/syslog.ph</em> library file. However, this wasn'tdone by default at Perl installation time. Later releases now use anXS interface, so the <em class="emphasis">sys/syslog.ph</em> preparation is no longer needed.</p><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch32_40.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch32_42.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">32.40. Sys::Hostname</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">32.42. Term::Cap</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright © 2001</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -