Skip to content

Instantly share code, notes, and snippets.

@samuelkordik
Created June 12, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelkordik/40d1b37950db348dc083 to your computer and use it in GitHub Desktop.
Save samuelkordik/40d1b37950db348dc083 to your computer and use it in GitHub Desktop.
errors.php
<?php
/**
* Functions for handling errors
*/
/**
* Logs error message to the app-specific error log.
*
* @package App
*/
function log_error($message){
/*
* Logs error message using the $message provided.
*/
//global $_errors, $a_log;
$remote_addr = (array_key_exists('REMOTE_ADDR', $_SERVER)) ? $_SERVER['REMOTE_ADDR'] : 'local';
$out = ' <' . $remote_addr . '> ' . date('M-j-H:i:s') . ' '. $message."\n\n";
if (LOG_ERRORS) {
error_log($out, 3, BASE_PATH.'/error_log.log');
}
//$a_log->appendError($out);
return true;
}
/**
* Custom error handler to write the error messages, log them, and save them on queue for emailing later.
*
* @package Core\Error Handling
*/
function error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
switch($errno){
case E_ERROR:
$message = 'E_ERROR';
break;
case E_USER_ERROR:
$message = 'E_USER_ERROR';
log_error($message . $errstr . ' in ' . $errfile . ' at ' . $errline);
//require_once(FULL_PATH_DEFAULT_ERROR_PAGE);
exit(1);
break;
case E_WARNING:
$message = 'E_WARNING';
break;
case E_USER_WARNING:
$message = 'E_USER_WARNING';
break;
case E_NOTICE:
$message = 'E_NOTICE';
break;
case E_USER_NOTICE:
$message = 'E_USER_NOTICE';
break;
default:
$message = FALSE;
}
if ($message) {
//global $a_log;
//$a_log->setSuccess($errno);
if (extension_loaded('newrelic')) {
newrelic_notice_error($errno, $errstr, $errfile, $errline);
}
if (RAYGUN) {
$tags = array('live');
global $client;
$client->SendError($errno, $errstr, $errfile, $errline, $tags);
}
log_error( $message .' '. $errstr . ' in ' . $errfile . ' at ' . $errline );
}
return true;
}
function exception_handler($exception)
{
if (RAYGUN) {
global $client;
$client->SendException($exception);
}
if (extension_loaded('newrelic')) {
newrelic_notice_error($exception->getMessage(), $exception);
}
}
set_exception_handler('exception_handler');
set_error_handler("error_handler");
/**
* Custom class used for sending messages out on a custom error page.
*
* @package Core\Error Handling
*/
class UserException extends Exception
{
function __construct($x) {
parent::__construct($x);
}
}
/**
* Custom class used for sending messages out on a custom error page.
*
* @package Core\Error Handling
*/
class PermissionsException extends Exception
{
function __construct($x) {
parent::__construct($x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment