📄 ch22_04.htm
字号:
<html><head><title>Win32::Eventlog (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch22_03.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch22_05.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">22.4. Win32::Eventlog</h2><p><a name="INDEX-3217" />This module makes the Windows NT eventlog accessible to your Perl programs. It allows you to create newrecords, read records, and create backup logfiles. The<tt class="literal">new</tt> constructor opens a server'sevent log as an object:</p><blockquote><pre class="code">$log = Win32::EventLog->new(<em class="replaceable"><tt>source</em>, [<em class="replaceable">server</tt></em>]);</pre></blockquote><p>This function opens an event log and returns an object reference.<em class="replaceable"><tt>source</tt></em> specifies the name of the sourceevent, and <em class="replaceable"><tt>server</tt></em> specifies the name ofthe server (<tt class="literal">local</tt> is assumed if no server name isgiven).</p><p>Many of the methods for this module require a reference to an emptyvariable as an argument. This is how the return value of the methodwill be placed, whether it is a hash or a scalar. The followingmethods can be used on event log objects.</p><a name="INDEX-3218" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Backup</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->Backup(<em class="replaceable">filename</em>)</pre><p><a name="INDEX-3218" />Saves the current open eventlog to a file named by <em class="replaceable"><tt>filename</tt></em>.</p></div><a name="INDEX-3219" /><a name="INDEX-3220" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Clear</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->Clear([<em class="replaceable">filename</em>])</pre><p><a name="INDEX-3219" />Writes the current event log to thefile <em class="replaceable"><tt>filename</tt></em> (if supplied) and clears theevent log.<a name="INDEX-3220" /> </p></div><a name="INDEX-3221" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>GetNumber</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->GetNumber(\$<em class="replaceable">number</em>)</pre><p><a name="INDEX-3221" />Returns the number of eventsas the value of the scalar variable<em class="replaceable"><tt>number</tt></em>.</p></div><a name="INDEX-3222" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>GetOldest</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->GetOldest(\$<em class="replaceable">record</em>)</pre><p><a name="INDEX-3222" />Returns the record number ofthe oldest record in the event log to the scalar<tt class="literal">$</tt><em class="replaceable"><tt>record</tt></em>.</p></div><a name="INDEX-3223" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Read</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->Read(<em class="replaceable">flags</em>, <em class="replaceable">offset</em>, \%<em class="replaceable">eventinfo</em>)</pre><p><a name="INDEX-3223" />Reads an entry from theevent log and returns the information in the<em class="replaceable"><tt>eventinfo</tt></em> hash.<em class="replaceable"><tt>offset</tt></em> specifies the record number youwant to start at in the log. <em class="replaceable"><tt>flags</tt></em> setsoptions for how you want to read the log, which can be anycombination of the following:</p><dl><dt><b><tt class="literal">EVENTLOG_FORWARDS_READ</tt></b></dt><dd>Eventlog is read in forward chronological order.</p></dd><dt><b><tt class="literal">EVENTLOG_BACKWARDS_READ</tt></b></dt><dd>Eventlog is read in reverse chronological order.</p></dd><dt><b><tt class="literal">EVENTLOG_SEEK_READ</tt></b></dt><dd>The read begins at the record specified by the<tt class="literal">$RecordOffset</tt> parameter. Must also specify<tt class="literal">EVENT_LOG_FORWARDS_READ</tt> or<tt class="literal">EVENTLOG_BACKWARDS_READ</tt>.</p></dd><dt><b><tt class="literal">EVENTLOG_SEQUENTIAL_READ</tt></b></dt><dd>The read continues sequentially from the last <tt class="literal">read</tt>call.</p></dd></dl><p>The final argument is the output object for the event read.<em class="replaceable"><tt>eventinfo</tt></em> is a reference to a hash thatcontains keys for each part of the event description. This samestructure is used when you report new events to the event log usingthe <tt class="literal">Report</tt> method. The<em class="replaceable"><tt>eventinfo</tt></em> hash looks like this:</p><blockquote><pre class="code">%event = ( EventID => <em class="replaceable"><tt>val</tt></em>, EventType => <em class="replaceable"><tt>val</tt></em>, Category => <em class="replaceable"><tt>val</tt></em>, ClosingRecordNumber => <em class="replaceable"><tt>val</tt></em>, Source => <em class="replaceable"><tt>val</tt></em>, Computer => <em class="replaceable"><tt>val</tt></em>, Strings => <em class="replaceable"><tt>val</tt></em>, Data => <em class="replaceable"><tt>val</tt></em>,);</pre></blockquote></div><a name="INDEX-3224" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Report</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">log</em>->Report(\%<em class="replaceable">eventinfo</em>)</pre><p><a name="INDEX-3224" />Reports an event to theevent log. The information for the event to be recorded is given in ahash, <tt class="literal">%eventinfo</tt>, which should contain values forat least the following keys:</p><dl><dt><b><tt class="literal">EventType</tt></b></dt><dd>A string describing the type of event to be reported. The options for<tt class="literal">EventType</tt> are:</p><blockquote><pre class="code">EVENTLOG_ERROR_TYPE Error event EVENTLOG_WARNING_TYPE Warning event EVENTLOG_INFORMATION_TYPE Information event EVENTLOG_AUDIT_SUCCESS_TYPE Success Audit event EVENTLOG_AUDIT_FAILURE_TYPE Failure Audit event</pre></blockquote></dd><dt><b><tt class="literal">Category</tt></b></dt><dd>An integer value for the category of the event, defined by theapplication.</p></dd><dt><b><tt class="literal">EventID</tt></b></dt><dd>Source-specific ID for the event.</p></dd><dt><b><tt class="literal">Data</tt></b></dt><dd>Raw binary data for the event.</p></dd><dt><b><tt class="literal">Strings</tt></b></dt><dd>Any text strings to merge that provide a description of the event.</p></dd></dl></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch22_03.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch22_05.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">22.3. Win32::ChangeNotify</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">22.5. Win32::File</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -