ErrorHandler.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\App;
  3. class ErrorHandler
  4. {
  5. const ERRORS = [1, 4, 16, 64, 256, 4096];
  6. const WARNINGS = [2, 32, 128, 512, 2048];
  7. const NOTICES = [8, 1024, 8192, 16384];
  8. public function __construct()
  9. {
  10. require_once __DIR__ . DIRECTORY_SEPARATOR . 'LowLevelLog.php';
  11. }
  12. public function logError($errorToken, $errno, $errstr, $errfile, $errline, $errcontext = null)
  13. {
  14. $logType = $this->getLogType($errno);
  15. $errorTime = date('d.m.Y H:i:s', time());
  16. $errorDetails = [
  17. 'errno' => $errno,
  18. 'errstr' => $errstr,
  19. 'errfile' => $errfile,
  20. 'errline' => $errline,
  21. 'errcontext' => $logType === 'error' ? $errcontext : null
  22. ];
  23. $log = new LowLevelLog($logType, $errorToken, $errorTime);
  24. $log->makeLogs($errorDetails);
  25. }
  26. public function getLogType($errno = null)
  27. {
  28. if (in_array($errno, self::WARNINGS))
  29. {
  30. return 'warning';
  31. }
  32. if (in_array($errno, self::NOTICES))
  33. {
  34. return 'notice';
  35. }
  36. return 'error';
  37. }
  38. }