ExceptionTrait.php 823 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/8/14
  6. * Time: 8:26 PM
  7. */
  8. namespace App\Handlers;
  9. trait ExceptionTrait
  10. {
  11. public static $LOG_DEV = 0;
  12. public static $LOG_COMMON = 1;
  13. public static $LOG_MAJOR = 2;
  14. public static $LOG_MAPS = [
  15. 'DEV',
  16. 'COMMON',
  17. 'MAJOR',
  18. ];
  19. protected static function log($mes, $type = 'log', $isDev = 0)
  20. {
  21. if (!Config['debug']) return '';
  22. if (is_array($mes)) $mes = json_encode($mes, true);
  23. if ($isDev === 0) return true;
  24. $log = self::$LOG_MAPS[$isDev];
  25. echo date('Y-m-d H:i:s') . "{{$log}}[{$type}]" . ' ==> ' . $mes . PHP_EOL;
  26. error_log(date('Y-m-d H:i:s') . "{{$log}}[{$type}]" . ' ==> ' . $mes . PHP_EOL, 3, __DIR__ . '/../../logs/error-' . date('Y-m-d') . '.log');
  27. }
  28. }