我试图从Laravel 4 artisan命令向raygun.io发送错误和异常,但Laravel似乎有它自己的异常处理程序。Artisan命令的自定义错误和异常处理程序
有没有办法让我在我的命令中指定一个自定义方法?目前,我想如下指定错误和异常的自定义处理程序:
<?php
class ParseCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'my:parse';
protected $descriptino = '...';
protected $raygun = null;
/**
* __construct
*/
public function __construct()
{
parent::__construct();
// Setup custom error and exception handlers
$raygun_api_key = \Config::get('tms.raygun_api_key');
$this->raygun = new RaygunClient("MUzf+furi8E9tffcHAaJVw==");
set_exception_handler([$this, 'exceptionHandler']);
set_error_handler([$this, 'errorHandler']);
}
/**
* Custom exception handler.
*
* @param $exception
*/
public function exceptionHandler($exception)
{
$this->raygun->SendException($exception);
}
/**
* Custom error handler.
*
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
*/
public function errorHandler($errno, $errstr, $errfile, $errline)
{
$this->raygun->SendError($errno, $errstr, $errfile, $errline);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$start_time = microtime(true);
throw new \Exception("Oopsie!");
// Omitted for brevity...
}
}
关过程中的处理程序从不执行,因为工匠用它自己的自定义实现抓住他们。
签入文件'app/start/global.php'。应该有一个Laravel使用的异常处理程序。它应该很容易修改。我在文档中找到了这个http://laravel.com/docs/errors#handling-errors,它应该会给你更多的信息。 – user3158900
相关:我写了[这个答案](https://stackoverflow.com/q/46819944/5209322)这可能有助于更新版本的Laravel。 –