4 years ago

Error logging is not working when user is logged in

Posted 4 years ago by saqueib

I am getting this weird issue, I have setup slack with Monolog and its sending notification, but when I am logged in there is no notification coming.

class AppServiceProvider extends ServiceProvider {

     * Bootstrap any application services.
     * @return void
    public function boot()
        if ($this->app->environment('production')) {
            // Get The Logger
            $monolog = Log::getMonolog();
            $monolog->pushProcessor(new WebProcessor($_SERVER));
            $monolog->pushProcessor(function ($record) {

                 $record['extra']['session_id'] = Cookie::get(config('session.cookie'));

                 // Auth::user() is always null, how can i get the logged in user
                 $record['extra']['user'] = \Auth::check() ? 'Name: '.\Auth::user()->name . "\n". url(\Auth::user()->username) : "Guest";
                 $record['extra']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
                 return $record;

            $slackHandler = new SlackHandler(env('SLACK_TOKEN'), '#sss-sslogs', 'sss-log', true, ':warning:', Logger::ERROR, true, false, true


I have tried with commenting out $record['extra']['user'] line from above but no luck, I need to logout to make it send notification.

How can i get the Auth::user() in AppServiceProvider its always returning null, or is there anywhere else I can register this SlackHandler

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