Code Snippets: How to log system messages in PHP

In PHP we are provided with an integrated logging system for outputting info, warnings, and errors. This is accomplished by use of the syslog function. This function outputs the specified message at the specified priority level to the default system logger. If you want to have it output the log message to a user defined log handler then you simply need to utilize the openlog and closelog functions before and after respectively before you log a message.

Example Log Statements

syslog(LOG_ERR, "message to be logged as an error");
openlog("AppLog", LOG_PERROR, LOG_LOCAL0);

// code

syslog(LOG_WARNING, "warning priority sample log message");

// code

closelog();

Resources

// Code Snippets // PHP //

Comments & Questions

Add Your Comment