php - Get Monolog JSON Stack Trace as Array -
i'm using laravel 4.2 , want logs out json. laravel uses monolog, i've configured json formatter so:
$loghandler = new monolog\handler\streamhandler(config::get('app.logfile'), monolog\logger::debug); $loghandler->setformatter(new monolog\formatter\jsonformatter); log::getmonolog()->pushhandler($loghandler);
the problem stack traces included part of message string, so:
{ "message": "exception 'exception' message 'socket operation failed: host name lookup failure' in /var/www/vendor/clue/socket-raw/socket/raw/socket.php:388\nstack trace:\n#0 /var/www/vendor/clue/socket-raw/so..." }
can point me in right direction make stack trace own separate array in json?
long overdue update:
the primary problem laravel, , lots of code following example, tries log exception itself, e.g., log::error($e)
. this wrong way log exception monolog. first parameter supposed simple message string. in processing it, monolog\logger::addrecord()
explicitly casts message string:
$record = array( 'message' => (string) $message, //... );
if $message
exception, whole stack trace string. unfortunately, laravel's default exception handler does.
the correct way stack trace array pass exception in context it's available non-stringified formatter. instance:
log::error($e->getmessage(), ['exception' => $e]);
something equivalent need put in custom exception handler laravel, , can use proper json formatter , except.
Comments
Post a Comment