Smilie's avatar

Logging processor

Hi, Does anybody have tips on how to include processors from https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#processors

Into my logs? And perhaps how to make my own processor? I'd like to log the sid from my token :) I'm guessing this could go into the extra's somehow..

0 likes
2 replies
Smilie's avatar

So I managed to solve this, mostly using the tap, config:

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'tap' => [\App\Logging\LogInjector::class]
        ],

And accompanied class:

use Illuminate\Support\Facades\Auth;
use Monolog\Logger;
use Monolog\Processor\IntrospectionProcessor;
use Monolog\Processor\WebProcessor;

class LogInjector
{
    /**
     * Customize the given logger instance.
     *
     * @param  \Illuminate\Log\Logger  $logger
     * @return void
     */
    public function __invoke($logger)
    {

        if (php_sapi_name() !== 'cli') {
            $logger->pushProcessor(new WebProcessor());
        }
        $logger->pushProcessor(new IntrospectionProcessor(Logger::DEBUG, ['Illuminate\']));

        dd(Auth::user());
    }
}

I'm still struggling with getting the SID though. I tried the Auth::user() but that just returns my user model, which does not hold the SID, as this is in the token. I can't seem to access the Request object, which would've been a way to retrieve it.

Would be nice to somehow get access to the Request, as I'm thinking about logging some of the headers as well.

judev's avatar

can you turn solved post pleaese :) Thank you.

Please or to participate in this conversation.