Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

JSON logger context

Hi all

I'm wokring with the formatter Phalcon\Logger\Formatter\Json and this works for the standard input for e.g error $logger->error("Message");

{"type":"ERROR","message":"Message","timestamp":1448102495}

I would like to extend this, to e.g. {"type":"ERROR","message":"Message","timestamp":1448102495,"userid":5}, but i can't figure out howto. I believe that at solution should include the $context array in the logger. So it would be something like this

$logger->error("Message",array('userid'=>5));

Any suggestions to make this?

Thanks in advance

BR Mads



107.2k
Accepted
answer
edited Nov '15

you can just do something like this:

$logger->error("Message".PHP_EOL.
jsen_encode(array('userid'=>5)));

I using writing it like this for json body from request and post data.