nevar/laravel-slack-error-logger

适用于低版本Laravel的简单Slack错误日志包

dev-master 2019-07-01 15:23 UTC

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任务)

  1. 安装 composer require nevar/laravel-slack-error-logger "@dev",

  2. 服务提供者 根据您的Laravel版本,将以下代码复制到config/app.php中,

return [
    /*
    * Application Service Providers...
    */
    Raven\Slack\Providers\SlackServiceProvider::class,
];

然后运行 php artisan config:cache.

  1. 配置 运行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_LOGGINGSLACK_ERROR_WEBHOOK 来覆盖自己的设置

  1. 别名 将以下别名添加到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.

  1. 实现 将以下行代码添加到您的异常处理程序中,位于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);
    }