L5 Monolog with Slack integration

Posted 4 years ago by khoanguyenme

I'm using Monolog with ChromePHP and now I want to integrate it with Slack but I can't config SlackHandler to works. In app\Providers\AppServiceProviders.php:

<?php namespace Quiz\Providers;

use Illuminate\Support\ServiceProvider;
use Log;

class AppServiceProvider extends ServiceProvider {

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Log::listen(function()
        {
            $monolog = Log::getMonolog();

            if (env('APP_ENV') === 'local')
            {
                $monolog->pushHandler($chromeHandler = new \Monolog\Handler\ChromePHPHandler());
                $chromeHandler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
            }

            $slackHandler = new \Monolog\Handler\SlackHandler(
                'my-api-token',
                'random'
            );
            $monolog->pushHandler($slackHandler);
            $slackHandler->setFormatter(new \Monolog\Formatter\LineFormatter());

        });
}

I get my-api-token at https://api.slack.com/web#auth Try to log somethings but only ChromePHP (and of course default Laravel file log works).

Is there anything wrong with my config? I also open a issue on Monolog's github but no response yet. https://github.com/Seldaek/monolog/issues/514

Please sign in or create an account to participate in this conversation.