Source of: /manual/en/function.syslog.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.network.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.syslog.php',
1 => 'syslog',
),
'up' =>
array (
0 => 'ref.network.php',
1 => 'Network Functions',
),
'prev' =>
array (
0 => 'function.socket-set-timeout.php',
1 => 'socket_set_timeout',
),
'next' =>
array (
0 => 'book.sam.php',
1 => 'SAM',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.syslog" class="refentry">
<div class="refnamediv">
<h1 class="refname">syslog</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">syslog</span> — <span class="dc-title">Generate a system log message</span></p>
</div>
<a name="function.syslog.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>syslog</b></span>
( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$priority</tt></span>
, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$message</tt></span>
)</div>
<p class="para rdfs-comment">
<b>syslog()</b> 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>
<a name="function.syslog.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">priority</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
<i><tt class="parameter">priority</tt></i>
is a combination of the facility and
the level. Possible values are:
</p><table class="doctable table">
<caption><b><b>syslog()</b> Priorities (in descending order)</b></caption>
<thead valign="middle">
<tr valign="middle">
<th>Constant</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_EMERG</tt></b></td>
<td align="left">system is unusable</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_ALERT</tt></b></td>
<td align="left">action must be taken immediately</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_CRIT</tt></b></td>
<td align="left">critical conditions</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_ERR</tt></b></td>
<td align="left">error conditions</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_WARNING</tt></b></td>
<td align="left">warning conditions</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_NOTICE</tt></b></td>
<td align="left">normal, but significant, condition</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_INFO</tt></b></td>
<td align="left">informational message</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">LOG_DEBUG</tt></b></td>
<td align="left">debug-level message</td>
</tr>
</tbody>
</table>
<p>
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">message</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The message to send, except that the two characters
<i>%m</i> will be replaced by the error message string
(strerror) corresponding to the present value of
<span class="errortype">errno</span>.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.syslog.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.syslog.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Using <b>syslog()</b></b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// open syslog, include the process ID and also send<br />// the log to standard error, and use a user defined<br />// logging mechanism<br /></span><span style="color: #0000BB">openlog</span><span style="color: #007700">(</span><span style="color: #DD0000">"myScriptLog"</span><span style="color: #007700">, </span><span style="color: #0000BB">LOG_PID </span><span style="color: #007700">| </span><span style="color: #0000BB">LOG_PERROR</span><span style="color: #007700">, </span><span style="color: #0000BB">LOG_LOCAL0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// some code<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">authorized_client</span><span style="color: #007700">()) {<br /> </span><span style="color: #FF8000">// do something<br /></span><span style="color: #007700">} else {<br /> </span><span style="color: #FF8000">// unauthorized client!<br /> // log the attempt<br /> </span><span style="color: #0000BB">$access </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y/m/d H:i:s"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">syslog</span><span style="color: #007700">(</span><span style="color: #0000BB">LOG_WARNING</span><span style="color: #007700">, </span><span style="color: #DD0000">"Unauthorized client: </span><span style="color: #0000BB">$access</span><span style="color: #DD0000"> </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"> (</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">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.syslog.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<p class="para">
On Windows NT, the syslog service is emulated using the Event
Log.
</p>
<blockquote><p><b class="note">Note</b>:
Use of <i>LOG_LOCAL0</i> through
<i>LOG_LOCAL7</i> for the <i><tt class="parameter">facility</tt></i>
parameter of <a href="function.openlog.php" class="function">openlog()</a> is not available
in Windows.
<br />
</p></blockquote>
</div>
<a name="function.syslog.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.openlog.php" class="function" rel="rdfs-seeAlso">openlog()</a> - Open connection to system logger</li>
<li class="member"><a href="function.closelog.php" class="function" rel="rdfs-seeAlso">closelog()</a> - Close connection to system logger</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>