123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace RTP\Module;
- class ExceptionModule extends \Exception
- {
-
- public function __construct($code = 10000, $info)
- {
-
- if (!file_exists('./log/'))
- {
-
- if (!mkdir('./log/'))
- {
-
- 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());
-
- 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 ;
- }
- }
- ?>
|