| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace common\helpers;
- use Exception;
- use Yii;
- /**
- * 错误助手类
- * @package common\helpers
- */
- final class ErrHelper
- {
- /**
- * 获取异常信息
- *
- * @param Exception $e
- * @return string
- */
- public static function getExceptionMsg(Exception $e)
- {
- return sprintf('错误文件: %s, 错误行数: %s, 错误内容: %s', $e->getFile(), $e->getLine(), $e->getMessage());
- }
- /**
- * 记录错误信息到日志
- *
- * @param string $msg
- * @param string $params
- * @return void
- */
- public static function log(string $title, Exception $e)
- {
- Yii::$app->custom->logs(
- $title . '「' . static::getExceptionMsg($e) . '」'
- );
- }
- }
|