How It’s Done
format. This will make things easier if we need to change the location, the filename and/or the
date format at a later time. In this example I will use /tmp/article.log because I am using my
development machine. Please, do not use /tmp on a production machine. Instead, have your admin s
et up a directory outside of the DocumentRoot that the server can write to, and you can read.
/tmp is normally chmod 777, meaning that anyone can read, write or execute from that directory.
This can be a major security hazard.
$log_file = '/tmp/article.log';
$date = date('Y-m-d H:i:s (T)');
very basic example. Of course, you are free to expand on this as you wish:
function simplisticErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
global $log_file, $date;
if ( $errno == E_USER_NOTICE )
$error = "$date - ".$_SERVER['REMOTE_ADDR']." - NOTICE: $errmsg in $filename on line $linenumn";
error_log( $error, 3, $log_file );
go into detail. If you are having a bit of an issue it’s probably best that you drop back a little,
until you are a little more familiar with PHP.
the way we want the error handled and finally the destination. The first argument is pretty self-explanatory,
as is the third. The second argument determines how PHP handles logging the file and, taken from
http://www.php.net/error_log, our current options are:
– 0 message is sent to PHP’s system logger, using the Operating System’s system logging mechanism or a file, depending on what the error_log configuration directive is set to.
– 1 message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used. This message type uses the same internal function as mail() does.
– 2 message is sent through the PHP debugging connection. This option is only available if remote debugging has been enabled. In this case, the destination parameter specifies the host name or IP address and optionally, port number, of the socket receiving the debug information.
– 3 message is appended to the file destination.