1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-17 15:55:31 +08:00
course-tencent-cloud/bootstrap/ConsoleErrorHandler.php
2025-03-11 18:48:58 +08:00

54 lines
1.0 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace Bootstrap;
use App\Library\Logger as AppLogger;
use Throwable;
class ConsoleErrorHandler extends ErrorHandler
{
public function __construct()
{
parent::__construct();
}
/**
* @param Throwable $e
*/
public function handleException($e)
{
$logger = $this->getLogger();
$content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage());
$logger->error($content);
$config = $this->getConfig();
if ($config->path('env') == 'dev' || $config->path('log.trace')) {
$trace = sprintf('Trace Content: %s', $e->getTraceAsString());
$logger->error($trace);
$content .= $trace;
}
echo $content . PHP_EOL;
}
protected function getLogger()
{
$logger = new AppLogger();
return $logger->getInstance('console');
}
}