Sentry.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chendeben
  5. * Date: 2017/12/6
  6. * Time: 11:55
  7. */
  8. namespace PhpLife\Library;
  9. use PhpLife\Config\Sentry as SentryConfig;
  10. use PhpLife\Frame\Request;
  11. require_once dirname(__DIR__) . '/Library/Raven/Autoloader.php';
  12. class Sentry
  13. {
  14. public static $instance;
  15. public $client;
  16. public function __construct($is_pre = FALSE)
  17. {
  18. \Raven_Autoloader::register();
  19. $opinion = [
  20. 'tags' => [
  21. 'php_version' => phpversion(),
  22. 'environment' => Request::getMode()
  23. ]
  24. ];
  25. $this->client = new \Raven_Client(SentryConfig::getData('url'), $opinion);
  26. }
  27. public static function instance()
  28. {
  29. if (!isset(self::$instance)) {
  30. $instance = new self();
  31. self::$instance = $instance;
  32. } else {
  33. $instance = self::$instance;
  34. }
  35. return $instance;
  36. }
  37. public function setException(){
  38. $error_handler = new \Raven_ErrorHandler($this->client);
  39. $error_handler->registerExceptionHandler();
  40. $error_handler->registerErrorHandler();
  41. $error_handler->registerShutdownFunction();
  42. // $this->client->install();
  43. }
  44. public function exceptionHandler($ee)
  45. {
  46. $error_handler = new \Raven_ErrorHandler($this->client);
  47. $error_handler->registerExceptionHandler();
  48. $error_handler->registerErrorHandler();
  49. $error_handler->registerShutdownFunction();
  50. $this->client->captureException($ee);
  51. }
  52. public function exMessage($msg)
  53. {
  54. $error_handler = new \Raven_ErrorHandler($this->client);
  55. $error_handler->registerExceptionHandler();
  56. $error_handler->registerErrorHandler();
  57. $error_handler->registerShutdownFunction();
  58. $this->client->captureMessage($msg);
  59. }
  60. }