samedi 5 mars 2016

Laravel 5.1: Logging nightmare

Within my application, I am running a stack of Node, Php and Redis. Node is listening on a Redis channel for JSON messages that form a log message. So up to this point, I have simply send log messages to the Redis server, to get them displayed in Node, since Node launches an instance of Workerman, which cuts standard output and standard input. So all I see from there is the message that Workerman is online. That is why I am using Redis to redirect my log messages to Node.

Unfortunately, I am running into a CSRF token mismatch error, and trying to properly print the exception has proven the limits of my logging: For some reason, the exception is logged twice. Tracking that isn't the problem, it's rather that the output explodes all over the screen and its hard to really make out what I am looking for - not to mention, that since there are two log-bombs incoming, the output gets kinda messed up too, since Node tries to log immediately after receiving.

That is where Laravel's normal logging comes into play. I know that it uses Monolog. But I have no experience with it. So what I would like to do is:

  • Log to a file, just for Laravel.
  • Also send log messages to my Redis broker - at least a few levels.
  • Pretty logging of exceptions in the file.

Currently, the exceptions seem to be mushed all together into a single line with zero line-breaks preserved. I have managed to tell Monolog to log to a specific location:

$app->configureMonologUsing(function($monolog) {
    $path = APP_ROOT."/log/BIRD3.laravel.log";
    \BIRD3\Backend\Log::info("Logs to: $path");
    $monolog->pushHandler(new StreamHandler($path));
});

BIRD3\Backend\Log is my Redis logger. I will rename it properly, when I get Monolog to work as I want it to.

But now I would like to log to my Redis logger whenever something is logged with Monolog. How do I do that, how do I attach handlers for the various levels? And, how do I get my exceptions printed properly, and not crunched together into a single line?


References/Infos:

  • Workerman: http://ift.tt/1IDZpvR
  • Laravel: Version 5.1.x as per composer.json
  • Redis: 3.0.7
  • Node: 5.7 (Via: n latest)
  • PHP: 7.0.4
  • OS: OS X


from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TWz29T
via IFTTT

Aucun commentaire:

Enregistrer un commentaire