我試圖從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。 –