We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



145.0k
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.