I’m trying to get a JSON output from monolog that’s a one level array with the different logged items, like this (when formatted):
[
{
"message": "test",
"context": {},
"level": 500,
"level_name": "CRITICAL",
"channel": "APP",
"datetime": "2024-06-16T08:31:26.931574-04:00",
"extra": {}
},
{
"message": "test",
"context": {},
"level": 500,
"level_name": "CRITICAL",
"channel": "APP",
"datetime": "2024-06-16T08:31:27.094920-04:00",
"extra": {}
}
]
I’ve searched around stackoverflow but haven’t found a solution yet for this type of output. I saw that you can have monolog pretty print the JSON but that’s not what I was looking for, I simply want it to append future logs to the end of the already created array.
I assume Monolog itself would have to realize that there’s previous logs and then prepend the comma before adding the new entry
Is this not possible in Monolog?
My handler code:
$handler = new StreamHandler( MY_PATH . '/logs/app.json' );
$handler->setFormatter( new JsonFormatter() );
$logger->pushHandler( $handler );
Using monolog 2.9