Log errors in the database

This commit is contained in:
Deon George 2013-04-09 14:47:27 +10:00
parent 52d9005b64
commit 6cb3e55ca9
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<?php defined('SYSPATH') OR die('No direct access');
/**
* Kohana exception class. Translates exceptions using the [I18n] class.
*
* @package OSB
* @category Modifications
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Kohana_Exception extends Kohana_Kohana_Exception {
/**
* Logs an exception in the database. If that fails fall back to Kohana's Logging.
*
* @uses Kohana_Exception::text
* @param Exception $e
* @param int $level
* @return void
*/
public static function log(Exception $e,$level=Log::EMERGENCY) {
try {
$eo = ORM::factory('Log_Error');
$eo->message = Kohana_Exception::text($e);
$eo->account_id = Auth::instance()->get_user()->id;
$eo->module = (Request::current()->directory() ? Request::current()->directory().'_' : '').Request::current()->controller();
$eo->method = Request::current()->action();
$eo->save();
} catch (Exception $x) {
return parent::log($e,$level);
}
}
/**
* Redirect errors to the main page after showing a system message.
* The error should be logged in the DB.
*
* @param Exception $e
* @return Response
*/
public static function response(Exception $e) {
try {
if (Kohana::$config->load('debug')->show_errors) {
return parent::response($e);
} else {
SystemMessage::add(array(
'title'=>'An Error Occured.',
'type'=>'error',
'body'=>'A error occured, which has been logged.',
));
// We'll redirect to the main page.
$response = Response::factory();
$response->status(302);
$response->headers('Location',URL::site());
return $response;
}
} catch (Exception $x) {
return parent::response($e);
}
}
}
?>

View File

@ -0,0 +1,14 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Log errors in the database.
*
* @package OSB
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Log_Error extends ORM_OSB {
}
?>

View File

@ -18,6 +18,7 @@ return array
'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item
'invoice'=>0, // Number of invoices to generate in a pass
'site'=>FALSE, // Glogal site debug
'show_errors'=>FALSE, // Show errors instead of logging in the DB.
'show_inactive'=>FALSE, // Show Inactive Items
'task_sim'=>FALSE, // Simulate running tasks
);