E
E
Eugene2021-12-07 12:02:21
symfony
Eugene, 2021-12-07 12:02:21

How to change Monolog Symfony logging format?

Good day!
There was a task to write logs with changes in a simple JSON format

{"datetime":"", "data":{"email":"", "user_id":""}

. You need to write logs through Monolog (you cannot write logs without a monologue).
It is written as $array - a simple archive that needs to be written as json The task that I want to solve is related to the fact that you need to get a log record without extra attributes that are created by a monologue.
$this->logger->log(LogLevel::INFO, '', $array));



{"message":"","context":"{datetime":"", "data":{"email":"", "user_id":""},"level":200,"level_name":"INFO","channel":"","datetime":{"date":"","timezone_type":3,"timezone":"Europe\/Berlin"},"extra":[]}


You need to remove from the log
- message
- context
- level
- level_name
- channel
- datetime

The output should have this format
{"datetime":"", "data":{"email":"", "user_id":""}
{"datetime":"", "data":{"email":"", "user_id":""}


Tell me how this can be implemented, perhaps an example of a formatter

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2021-12-07
@djon_pulse

You can create your own Formatter
https://github.com/Seldaek/monolog/blob/main/doc/0...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question