<!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><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-set-timeout.html">socket_set_timeout</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.rrd.html">RRD</a></div> <div class="up"><a href="ref.network.html">Network Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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> <div class="refsect1 description" id="refsect1-function.syslog-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <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> )</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">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">priority</code></em></span> <dd> <p class="para"> <em><code class="parameter">priority</code></em> 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> <dt> <span class="term"><em><code class="parameter">message</code></em></span> <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> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.syslog-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.syslog-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4496"> <p><strong>Example #1 Using <span class="function"><strong>syslog()</strong></span></strong></p> <div class="example-contents"> <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> </div> <div class="refsect1 notes" id="refsect1-function.syslog-notes"> <h3 class="title">Notes</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 <em><code class="parameter">facility</code></em> parameter of <span class="function"><a href="function.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">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.openlog.html" class="function" rel="rdfs-seeAlso">openlog()</a> - Open connection to system logger</span></li> <li class="member"> <span class="function"><a href="function.closelog.html" class="function" rel="rdfs-seeAlso">closelog()</a> - Close connection to system logger</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-set-timeout.html">socket_set_timeout</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.rrd.html">RRD</a></div> <div class="up"><a href="ref.network.html">Network Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>