uTools-Manuals/docs/php/syslog.html
2019-04-28 19:00:34 +08:00

186 lines
8.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Generate a system log message</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.syslog" class="refentry">
<div class="refnamediv">
<h1 class="refname">syslog</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">syslog</span> &mdash; <span class="dc-title">Generate a system log message</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.syslog-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>syslog</strong></span>
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$priority</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>
) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>syslog()</strong></span> generates a log message that will be
distributed by the system logger.
</p>
<p class="para">
For information on setting up a user defined log handler, see the
<span class="citerefentry"><span class="refentrytitle">syslog.conf</span>
<span class="manvolnum">(5)</span></span> Unix manual page. More
information on the syslog facilities and option can be found in the man
pages for <span class="citerefentry"><span class="refentrytitle">syslog</span>
<span class="manvolnum">(3)</span></span> on Unix machines.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.syslog-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">priority</code></dt>
<dd>
<p class="para">
<code class="parameter">priority</code> is a combination of the facility and
the level. Possible values are:
<table class="doctable table">
<caption><strong><span class="function"><strong>syslog()</strong></span> Priorities (in descending order)</strong></caption>
<thead>
<tr>
<th>Constant</th>
<th>Description</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td><strong><code>LOG_EMERG</code></strong></td>
<td>system is unusable</td>
</tr>
<tr>
<td><strong><code>LOG_ALERT</code></strong></td>
<td>action must be taken immediately</td>
</tr>
<tr>
<td><strong><code>LOG_CRIT</code></strong></td>
<td>critical conditions</td>
</tr>
<tr>
<td><strong><code>LOG_ERR</code></strong></td>
<td>error conditions</td>
</tr>
<tr>
<td><strong><code>LOG_WARNING</code></strong></td>
<td>warning conditions</td>
</tr>
<tr>
<td><strong><code>LOG_NOTICE</code></strong></td>
<td>normal, but significant, condition</td>
</tr>
<tr>
<td><strong><code>LOG_INFO</code></strong></td>
<td>informational message</td>
</tr>
<tr>
<td><strong><code>LOG_DEBUG</code></strong></td>
<td>debug-level message</td>
</tr>
</tbody>
</table>
</p>
</dd>
<dt>
<code class="parameter">message</code></dt>
<dd>
<p class="para">
The message to send, except that the two characters
<em>%m</em> will be replaced by the error message string
(strerror) corresponding to the present value of
<span class="errortype">errno</span>.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.syslog-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.syslog-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5506">
<p><strong>Example #1 Using <span class="function"><strong>syslog()</strong></span></strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;open&nbsp;syslog,&nbsp;include&nbsp;the&nbsp;process&nbsp;ID&nbsp;and&nbsp;also&nbsp;send<br />//&nbsp;the&nbsp;log&nbsp;to&nbsp;standard&nbsp;error,&nbsp;and&nbsp;use&nbsp;a&nbsp;user&nbsp;defined<br />//&nbsp;logging&nbsp;mechanism<br /></span><span style="color: #0000BB">openlog</span><span style="color: #007700">(</span><span style="color: #DD0000">"myScriptLog"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">LOG_PID&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">LOG_PERROR</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">LOG_LOCAL0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;some&nbsp;code<br /><br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">authorized_client</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;do&nbsp;something<br /></span><span style="color: #007700">}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;unauthorized&nbsp;client!<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;log&nbsp;the&nbsp;attempt<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$access&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y/m/d&nbsp;H:i:s"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">syslog</span><span style="color: #007700">(</span><span style="color: #0000BB">LOG_WARNING</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Unauthorized&nbsp;client:&nbsp;</span><span style="color: #0000BB">$access</span><span style="color: #DD0000">&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'REMOTE_ADDR'</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;(</span><span style="color: #007700">{</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">]}</span><span style="color: #DD0000">)"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">closelog</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.syslog-notes">
<h3 class="title">注释</h3>
<p class="para">
On Windows NT, the syslog service is emulated using the Event
Log.
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
Use of <em>LOG_LOCAL0</em> through
<em>LOG_LOCAL7</em> for the <code class="parameter">facility</code>
parameter of <span class="function"><a href="openlog.html" class="function">openlog()</a></span> is not available
in Windows.
</p>
</p></blockquote>
</div>
<div class="refsect1 seealso" id="refsect1-function.syslog-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="openlog.html" class="function" rel="rdfs-seeAlso">openlog()</a> - Open connection to system logger</span></li>
<li class="member"><span class="function"><a href="closelog.html" class="function" rel="rdfs-seeAlso">closelog()</a> - 关闭系统日志链接</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>