123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * @name eolinker ams open source,eolinker开源版本
- * @link https://www.eolinker.com/
- * @package eolinker
- * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
- * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
- * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
- *
- * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
- *
- * 官方网站:https://www.eolinker.com/
- * 官方博客以及社区:http://blog.eolinker.com/
- * 使用教程以及帮助:http://help.eolinker.com/
- * 商务合作邮箱:market@eolinker.com
- * 用户讨论QQ群:284421832
- */
- namespace RTP\Module;
- class ExceptionModule extends \Exception
- {
- /**
- * 构造方法,传递错误信息以及错误码
- */
- public function __construct($code = 10000, $info)
- {
- //如果记录文件夹不存在则新建
- if (!file_exists('./log/'))
- {
- //如果新建失败则抛出异常,可能权限不足
- if (!mkdir('./log/'))
- {
- //此处不用ExceptionModule进行异常抛出,因为如果权限不足,此异常会无限抛出进入死循环
- throw new \Exception("can not create directory,please check you app's root file system authorization", 13001);
- }
- }
- parent::__construct($info, $code);
- }
- public function printError($isStop = FALSE)
- {
- //如果非调试模式,则取消所有的错误输出
- if (!DEBUG)
- {
- $infoJson = array('errorCode' => $this -> getCode());
- //输出json
- echo json_encode($infoJson);
- $infoJson = array(
- 'datetime' => date('Y/M/d H:i:s', time()),
- 'errorCode' => $this -> getCode(),
- 'info' => $this -> getMessage(),
- 'wrongFile' => $this -> getFile(),
- 'wrongLine' => $this -> getLine()
- );
- //将错误信息记录到文件
- $logInfo = "{$infoJson['datetime']}=>[code:{$infoJson['errorCode']};info:{$infoJson['info']};wrongFile:{$infoJson['wrongFile']};wrongLine:{$infoJson['wrongLine']}];\n";
- file_put_contents('./log/' . date('Y_M_d', time()) . '.txt', $logInfo, FILE_APPEND);
- }
- else
- {
- $infoJson = array(
- 'datetime' => date('Y/M/d H:i:s', time()),
- 'errorCode' => $this -> getCode(),
- 'info' => $this -> getMessage(),
- 'wrongFile' => $this -> getFile(),
- 'wrongLine' => $this -> getLine()
- );
- //输出自然语言
- printFormatted($infoJson);
- $logInfo = "{$infoJson['datetime']}=>[code:{$infoJson['errorCode']};info:{$infoJson['info']};wrongFile:{$infoJson['wrongFile']};wrongLine:{$infoJson['wrongLine']}];\n";
- file_put_contents('./log/' . date('Y_M_d', time()) . '.txt', $logInfo, FILE_APPEND);
- }
- if ($isStop)
- exit ;
- }
- }
- ?>
|