-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gaowei
committed
May 28, 2022
1 parent
e544ed4
commit 74ea995
Showing
6 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +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]> | ||
* @date 2022-05-26 | ||
* | ||
* @copyright gaowei | ||
* | ||
*/ | ||
|
||
namespace GaoweiSpace\ErrorHandler; | ||
|
@@ -17,18 +16,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 = []) | ||
|
@@ -91,9 +90,9 @@ public function handleException(\Throwable $exception) | |
|
||
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) | ||
|
@@ -109,7 +108,7 @@ private function _log($type, $message) | |
} | ||
|
||
if ($this->display_errors) { | ||
print "{$level}: {$message}"; | ||
echo "{$level}: {$message}"; | ||
} | ||
} | ||
|
||
|
@@ -130,6 +129,7 @@ private function _sentry(\Throwable $exception) | |
private function _formatMessage($message, $file, $line, $trace = '') | ||
{ | ||
$message = "{$file}#{$line}: {$message}"; | ||
|
||
return <<<MSG | ||
$message | ||
$trace | ||
|