<?php
/**
* Log PHP's error into separate files. Recommended for use in production site.
* Should be used in set_error_handler() to handle certain PHP errors (i.e. E_STRICT).
* @link http://www.php.net/manual/en/function.set-error-handler.php Reference
*/
function errorHandler($errno, $errstr, $errfile=NULL, $errline=NULL, $errcontext=NULL) {
// Log uncategorized errors
if (is_null($errfile)) {
$errfile = 'errors.log';
}
// Reconstruct the path
// define('APP_DIR', '/my/application/')
// define('LOG_DIR', '/log_dir/')
// E.g. /my/application/controller/index.php -> /log_dir/controller/index.php
$pos = strpos($errfile, APP_DIR);
if ($pos !== FALSE) {
// Strip off the application directory and attach log directory
$errfile = LOG_DIR.substr($errfile, $pos + strlen(CMS_ROOT));
}
else {
$errfile = LOG_DIR.$errfile; // E.g. /log_dir/errors.log
}
$dir = dirname($errfile);
// Create dir if necessary
if (! file_exists($dir)) {
mkdir($dir, 0775, TRUE);
}
$logFile = fopen($errfile, 'a');
fwrite($logFile, date('Y-m-d H:i:s ').$errstr);
if ($errline) fwrite($logFile, " on line $errline");
fwrite($logFile, "\n");
fclose($logFile);
if (PRODUCTION_SITE) // Prevent err msg from being printed out (log errors silently)
return TRUE;
return FALSE;
}
?>
php
1
<?php/** * Log PHP's error into separate files. Recommended for use in production site. * Should be used in set_error_handler() to handle certain PHP errors (i.e. E_STRICT). * @link http://www.php.net/manual/en/function.set-error-handler.php Reference */functionerrorHandler($errno,$errstr,$errfile=NULL,$errline=NULL,$errcontext=NULL){// Log uncategorized errorsif(is_null($errfile)){$errfile='errors.log';}// Reconstruct the path// define('APP_DIR', '/my/application/')// define('LOG_DIR', '/log_dir/')// E.g. /my/application/controller/index.php -> /log_dir/controller/index.php$pos=strpos($errfile,APP_DIR);if($pos!==FALSE){// Strip off the application directory and attach log directory$errfile=LOG_DIR.substr($errfile,$pos+strlen(CMS_ROOT));}else{$errfile=LOG_DIR.$errfile;// E.g. /log_dir/errors.log}$dir=dirname($errfile);// Create dir if necessaryif(!file_exists($dir)){mkdir($dir,0775,TRUE);}$logFile=fopen($errfile,'a');fwrite($logFile,date('Y-m-d H:i:s ').$errstr);if($errline)fwrite($logFile," on line $errline");fwrite($logFile,"\n");fclose($logFile);if(PRODUCTION_SITE)// Prevent err msg from being printed out (log errors silently)returnTRUE;returnFALSE;}?>
Hey there! I see you're running Internet Explorer 6.
That's neat. This reminds me of my grandpa. He had this old car that he kept having to fix. He spent so much money on it that he didn't want to get rid of it (even when it stopped running).
0 Comments