Generate a system log message
Syntax
syslog(int $priority, string $message): bool
Parameters
priority
A combination of the facility and the level.
Constant (descending order) | 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.
Return
Returns true on success or false on failure.
Examples
1
<? // open syslog, include the process ID and send the log to standard error, and use a user defined logging mechanism $prefix = "myScriptLog"; $flags = LOG_PID | LOG_PERROR; $facility = LOG_LOCAL0; openlog($prefix, $flags, $facility); if(authorized_client()) { echo "do something"; } else { $priority = LOG_WARNING; $access = date("Y/m/d H:i:s"); $message = "unauthorized client: $access {$_SERVER['REMOTE_ADDR']} ({$_SERVER['HTTP_USER_AGENT']})"; $return = syslog($priority, $message); echo $return; } closelog(); ?>
2
<? $facilities = array( LOG_AUTH, LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_KERN, LOG_LOCAL0, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP, ); foreach($facilities as $facility) { $prefix = "test"; $flags = LOG_PID; openlog($prefix, $flags, $facility); $priority = LOG_ERR; $message = $flags . ": " . $facility; $return = syslog($priority, $message); echo $message . PHP_EOL; closelog(); } ?>
1: 32 1: 80 1: 72 1: 24 1: 0 1: 128 1: 48 1: 16 1: 56 1: 40 1: 8 1: 64