集成 laravel 7 记录到 slack

Integration laravel 7 log to slack

我尝试将错误日志 laravel 集成到松弛通知中。但是当我测试发送日志时,它无法向 slack 发送消息。我遵循了本教程 https://panjeh.medium.com/send-laravel-6-log-to-slack-notification-573a6d95a14e。我也在路线上测试过

这是config.php

'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single','slack'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 14,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'warning',
        ],

这是测试路线

Route::get('slack', function() {
    Log::error('Test');
    return 'Slack notif';
});

我也有 url 并把它放在 .env LOG_SLACK_WEBHOOK_URL=

您可以将默认日志通道更改为 slack.So 您必须设置

LOG_CHANNEL=stack 

您也可以指定频道。而不是换频道

Log::channel('slack')->inf("test");

或者你也可以

Log::stack(['daily', 'slack'])->info("test");

或者您可以在每日 array.So 中指定不需要更改任何频道的频道

 'stack' => [
        'driver' => 'stack',
        'channels' => ['daily', 'slack'],
        'ignore_exceptions' => false,
    ],