/** * Standardise the dumping of an exception message into the kohana log. E.g. * try { * ... code that throws exception ... * } catch (Exception $e) { * error::log_error('Error occurred whilst running some code', $e); * } * * @param string $msg A description of where the error occurred. * $param object $e The exception object. */ public static function log_error($msg, $e) { kohana::log('error', '#' . $e->getCode() . ': ' . $msg . '. ' . $e->getMessage() . ' at line ' . $e->getLine() . ' in file ' . $e->getFile()); // Double check the log threshold to avoid unnecessary work. if (kohana::config('config.log_threshold') == 4) { $trace = $e->getTrace(); $output = "Stack trace:\n"; for ($i = 0; $i < count($trace); $i++) { if (array_key_exists('file', $trace[$i])) { $file = $trace[$i]['file']; } else { $file = 'Unknown file'; } if (array_key_exists('line', $trace[$i])) { $line = $trace[$i]['line']; } else { $line = 'Unknown'; } if (array_key_exists('function', $trace[$i])) { $function = $trace[$i]['function']; } else { $function = 'Unknown function'; } $output .= "\t" . $file . ' - line ' . $line . ' - ' . $function . "\n"; } kohana::log('debug', $output); kohana::log_save(); } }