Skip to content

Commit

Permalink
fix: edit style
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowei committed Aug 1, 2022
1 parent 577c317 commit b9786e6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

/**
* ErrorHandler is used to catch all php runtime errors and supports reporting to monolog or sentry
* ErrorHandler is used to catch all php runtime errors and supports reporting to monolog or sentry.
*
* @author gaowei <[email protected]>
*
* @version 1.0.2
*
* @copyright gaowei
* @created_at 2022-05-26
* @updated_at 2022-08-01
Expand All @@ -18,18 +20,18 @@
class ErrorHandler
{
public $logger;
public $handler = 'logger'; // logger | sentry
public $handler = 'logger'; // logger | sentry
public $display_errors = false;
public $sentry_options = [];
public $report_level = E_ALL;
public $report_level = E_ALL;

public function __construct(array $options = [])
{
$this->display_errors = $options['display_errors'];
$this->handler = $options['handler'];
$this->logger = $options['logger'];
$this->handler = $options['handler'];
$this->logger = $options['logger'];
$this->sentry_options = $options['sentry_options'];
$this->report_level = $options['report_level'];
$this->report_level = $options['report_level'];
}

public static function init(array $options = [])
Expand All @@ -45,6 +47,7 @@ public static function init(array $options = [])
public static function create(array $options = [])
{
self::_setDefaultOptions($options);

return new static($options);
}

Expand Down Expand Up @@ -104,9 +107,9 @@ public function captureMessage(string $message, string $level)

private function _register()
{
register_shutdown_function(array($this, 'handleFatalError'));
set_error_handler(array($this, 'handleError'));
set_exception_handler(array($this, 'handleException'));
register_shutdown_function([$this, 'handleFatalError']);
set_error_handler([$this, 'handleError']);
set_exception_handler([$this, 'handleException']);
}

private function _log($type, $message)
Expand All @@ -116,7 +119,7 @@ private function _log($type, $message)
$this->_logWrite($message, $level);

if ($this->display_errors) {
print "{$level}: {$message}";
echo "{$level}: {$message}";
}
}

Expand Down

0 comments on commit b9786e6

Please sign in to comment.