nevar / laravel-slack-error-logger
适用于低版本Laravel的简单Slack错误日志包
dev-master
2019-07-01 15:23 UTC
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^6.2
- laravel/framework: >=5.3 <5.5
This package is auto-updated.
Last update: 2024-09-22 01:44:03 UTC
README
适用于低版本Laravel的简单Slack错误日志包
注意:Laravel版本高于5.5的版本已经内置了此功能;因此,当需要快速修复此功能时,请使用此包。否则,请更新您的Laravel版本。
此外,在生产环境中,将队列驱动程序从QUEUE_DRIVER=sync
更改为QUEUE_DRIVER=redis
也是一个好主意(此包依赖于Laravel任务)
-
安装
composer require nevar/laravel-slack-error-logger "@dev"
, -
服务提供者 根据您的Laravel版本,将以下代码复制到
config/app.php
中,
return [ /* * Application Service Providers... */ Raven\Slack\Providers\SlackServiceProvider::class, ];
然后运行 php artisan config:cache
.
- 配置 运行
php artisan vendor:publish --tag=raven-slack-error-logger
以发布配置文件config\slack.php
,它应该看起来像这样。
return [ /** * --------------------------------------------------------------------------------------------------- * slack base uri * --------------------------------------------------------------------------------------------------- */ 'base_uri' => 'https://hooks.slack.com', /** * --------------------------------------------------------------------------------------------------- * Enable\disable the error logger default is *true* * --------------------------------------------------------------------------------------------------- */ 'enable_error_logging' => env('SLACK_ENABLE_ERROR_LOGGING',true), /** * --------------------------------------------------------------------------------------------------- * Your slack channel web hook visit https://api.slack.com/incoming-webhooks for more * information on how to acquire one * --------------------------------------------------------------------------------------------------- */ 'error_web_hook' => env('SLACK_ERROR_WEBHOOK','/services/ABCD/EFGH/ijklmnopqrst') ];
然后通过添加 SLACK_ENABLE_ERROR_LOGGING
和 SLACK_ERROR_WEBHOOK
来覆盖自己的设置
- 别名 将以下别名添加到
config/app.php
return [ /* |-------------------------------------------------------------------------- | Class Aliases |-------------------------------------------------------------------------- | | This array of class aliases will be registered when this application | is started. However, feel free to register as many as you wish as | the aliases are "lazy" loaded so they don't hinder performance. | */ 'Slack' => Raven\Slack\Facades\Slack::class, ];
然后再次运行 php artisan config:cache
.
- 实现 将以下行代码添加到您的异常处理程序中,位于
app\Exceptions\Handler.php
/** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Exception $exception * @return void */ public function report(Exception $exception) { \Slack::log_error($exception); parent::report($exception); }