我试图通过Laravel4artisan命令向raygun.io发送错误和异常,但是Laravel似乎有自己的异常处理程序。
有什么方法可以让我在命令中指定自定义方法吗?目前,我正试图为错误和异常指定一个自定义处理程序,如下所示:
<?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...
}
}当然,处理程序永远不会执行,因为Artisan正在用它自己的自定义实现来捕获它们。
发布于 2014-04-14 20:04:31
在运行相应的环境时,只有在启动Laravel框架时才执行文件夹app/start中的文件。这意味着当环境等于local时运行local,当环境等于staging时运行app/start/staging.php。此外,每次运行app/start/global.php文件,在每个手工执行时运行app/start/artisan.php。
从文档中:http://laravel.com/docs/errors放置处理程序
App::error(function(Exception $exception)
{
Log::error($exception);
});在app/start/artisan中,您的手工只使用异常处理程序。
https://stackoverflow.com/questions/23067234
复制相似问题