syslog

(PHP 4, PHP 5)

syslog — Generate a system log message

Descrição

boolsyslog
( int$priority
, string$message
)

syslog() generates a log message that will be
distributed by the system logger.

For information on setting up a user defined log handler, see the
syslog.conf(5) Unix manual page. More
information on the syslog facilities and option can be found in the man
pages for syslog(3) on Unix machines.

Parâmetros

priority

priority is a combination of the facility and
the level. Possible values are:

syslog() Priorities (in descending order)

Constant

Description

LOG_EMERG

system is unusable

LOG_ALERT

action must be taken immediately

LOG_CRIT

critical conditions

LOG_ERR

error conditions

LOG_WARNING

warning conditions

LOG_NOTICE

normal, but significant, condition

LOG_INFO

informational message

LOG_DEBUG

debug-level message

message

The message to send, except that the two characters
%m will be replaced by the error message string
(strerror) corresponding to the present value of
errno.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em caso de falha.

Exemplos

Exemplo #1 Using syslog()

<?php// open syslog, include the process ID and also send// the log to standard error, and use a user defined// logging mechanismopenlog("myScriptLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);

A word of warning; if you use openlog() to ready syslog() and your Apache threads accept multiple requests, you *must* call closelog() if Apache's error log is configured to write to syslog. Failure to do so will cause Apache's error log to write to whatever facility/ident was used in openlog.

This *does* actually goto the system log as configured in /etc/syslog.conf (such as /var/log/messages), it doesn't goto Apache's ErrorLog (such as /var/log/httpd/error_log). At least under my Debian Potato with Apache 1.3.23.

man 3 syslog defines the priorities, but not the integer values. For that you'll need to read your system header file.

Let's suppose I want to log an informational message in the mail log (which happens to be true). The man page tells me I want LOG_MAIL|LOG_INFO. So I look in /usr/include/sys/syslog.h and find (this happens to be Linux, your system could be different):

Be aware when using syslog() that if you set the timezone of environment to be something other than the standard, syslog() may log the time to the log(s) with the wrong time zone information. For example:

I had a problem trying to issue a syslog message with IIS 5.1 under Windows XP. The function call seemed to succeed, but the event viewer showed that no entry was made.Finally I found out that the user account used for the webserver (IUSR_<Computername>) did not have enough permissions to issue syslog alerts. I changed this by adding this user to the Users group instead of only Guest.