Add custom error handler to log through new logging code
This commit is contained in:
@@ -71,4 +71,13 @@ define('Sihnon_ConfigTable', 'settings');
|
|||||||
*/
|
*/
|
||||||
define('Sihnon_ConfigFile', '../private/settings.txt');
|
define('Sihnon_ConfigFile', '../private/settings.txt');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sihnon Development Mode
|
||||||
|
*
|
||||||
|
* Specifies whether or not the Framework should operate in debug mode
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
define('Sihnon_Dev', true);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -117,6 +117,11 @@ class SihnonFramework_LogEntry {
|
|||||||
$logger->log($entry);
|
$logger->log($entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function logInternal($logger, $severity, $file, $line, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
|
||||||
|
$entry = new self($severity, $category, time(), getmypid(), $file, $line, $message);
|
||||||
|
$logger->log($entry);
|
||||||
|
}
|
||||||
|
|
||||||
public static function debug($logger, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
|
public static function debug($logger, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
|
||||||
static::log($logger, SihnonFramework_Log::LEVEL_DEBUG, $message, $category);
|
static::log($logger, SihnonFramework_Log::LEVEL_DEBUG, $message, $category);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,37 @@ class SihnonFramework_Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function initialise() {
|
public static function initialise() {
|
||||||
|
// Provide a means to load framework classes autonomously
|
||||||
spl_autoload_register(array('SihnonFramework_Main','autoload'));
|
spl_autoload_register(array('SihnonFramework_Main','autoload'));
|
||||||
|
|
||||||
|
// Handle error messages using custom error handler
|
||||||
|
set_error_handler(array(get_called_class(), 'errorHandler'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function errorHandler($errno, $errstr, $errfile = '', $errline = 0, $errcontext = array()) {
|
||||||
|
$severity = '';
|
||||||
|
switch ($errno) {
|
||||||
|
case E_NOTICE:
|
||||||
|
case E_USER_NOTICE:
|
||||||
|
$severity = SihnonFramework_Log::LEVEL_INFO;
|
||||||
|
break;
|
||||||
|
case E_WARNING:
|
||||||
|
case E_USER_WARNING:
|
||||||
|
$severity = SihnonFramework_Log::LEVEL_WARNING;
|
||||||
|
break;
|
||||||
|
case E_ERROR:
|
||||||
|
case E_USER_ERROR:
|
||||||
|
$severity = SihnonFramework_Log::LEVEL_ERROR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$severity = SihnonFramework_Log::LEVEL_INFO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SihnonFramework_LogEntry::logInternal(static::instance()->log(), $severity, $errfile, $errline, $errstr, SihnonFramework_Log::CATEGORY_DEFAULT);
|
||||||
|
|
||||||
|
// If dev mode is enabled, fail here to enable the normal PHP error handling
|
||||||
|
return ! Sihnon_Dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function autoload($classname) {
|
public static function autoload($classname) {
|
||||||
@@ -227,6 +257,21 @@ class SihnonFramework_Main {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function rmdir_recursive($dir) {
|
||||||
|
if (is_dir($dir)) {
|
||||||
|
$objects = scandir($dir);
|
||||||
|
foreach ($objects as $object) {
|
||||||
|
if ($object != "." && $object != "..") {
|
||||||
|
if (filetype($dir."/".$object) == "dir") self::rmdir_recursive($dir."/".$object); else unlink($dir."/".$object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reset($objects);
|
||||||
|
rmdir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static function issetelse($var, $default = null) {
|
public static function issetelse($var, $default = null) {
|
||||||
if (isset($var)) {
|
if (isset($var)) {
|
||||||
return $var;
|
return $var;
|
||||||
|
|||||||
Reference in New Issue
Block a user