/** * @inheritdoc */ public function init() { parent::init(); $this->module->registerFunction('exception', function (\Exception $e) { $entry = $this->module->getEntry(true); return $entry ? AuditError::log($entry, $e) : false; }); $this->module->registerFunction('errorMessage', function ($message, $code = 0, $file = '', $line = 0, $trace = []) { $entry = $this->module->getEntry(true); return $entry ? AuditError::logMessage($entry, $message, $code, $file, $line, $trace) : false; }); }
public function logException($exception) { try { $auditing = Auditing::current(); // Make sure not to interfere with out of memory errors, there's not enough spare room to load everything if ($auditing && strncmp($exception->getMessage(), 'Allowed memory size of', 22)) { $entry = $auditing->getEntry(true); if ($entry) { AuditError::log($entry, $exception); $entry->finalize(); } } } catch (\Exception $e) { } parent::logException($exception); }
/** * @param Exception $exception */ public function logException($exception) { try { // Make sure not to interfere with out of memory errors, there's not enough spare room to load everything if (strncmp($exception->getMessage(), 'Allowed memory size of', 22) == 0) { return; } /** @var Audit $audit */ $audit = Yii::$app->getModule('audit'); if ($audit) { $entry = $audit->getEntry(true); if ($entry) { AuditError::log($entry, $exception); $entry->finalize(); } } } catch (\Exception $e) { } parent::logException($exception); }
/** * @param Exception $exception */ public function logException($exception) { try { $isMemoryError = strncmp($exception->getMessage(), 'Allowed memory size of', 22) === 0; $module = Audit::getInstance(); if (!$module && !$isMemoryError) { // Only attempt to load the module if this isn't an out of memory error, not enough room otherwise $module = \Yii::$app->getModule(Audit::findModuleIdentifier()); } if (!$module) { throw new \Exception('Audit module cannot be loaded'); } $entry = $module->getEntry(!$isMemoryError); if ($entry) { AuditError::log($entry, $exception); $entry->finalize(); } } catch (\Exception $e) { // if we catch an exception here, let it slide, we don't want recursive errors killing the script } parent::logException($exception); }