K
K
Konstantin2017-03-01 11:49:29
symfony
Konstantin, 2017-03-01 11:49:29

How to properly organize logging in a monolithic web application?

Hello.
I have a medium-sized monolithic application written in symfony (~150 services), monolog is used for logging.
Almost every service has operations logging (the logger is injected as a dependency) and there was a problem with filtering messages by sender.
Let's say two services have code like this:

// AService
$this->logger->info("Message sent to {user}", ['user' => $user]);
// BService
$this->logger->info("Message sent to {user}", ['user' => $user]);

In the log file, I would like to understand which service sent this line and what preceded it in the context of this service.
What solutions do I see to the problem:
1. Write a label in each service in each message:
// AService
$this->logger->info("{service} some message", ['service' => __CLASS__]);
$this->logger->info("{service} another message", ['service' => __CLASS__]);

2. Implement your own logger configured for a specific channel into each service.
3. Write your own logger, which will receive a backtrace in the log method, get the class in which the logger method was called from there, and add it to the message.
In general, I do not like all three options.
The first one will turn out to be too much routine work and copy-paste.
In the second, the number of loggers will be equal to the number of services (and this is more than a hundred), which will need to be supported somehow, do not forget to create your own logger for it when starting a new service, this will swell the container.
In the third, I do not like the performance of the solution and its general crutchness.
Please share your thoughts on this. How would you organize logging in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2017-03-01
@BoShurik

Second option
Just do not create your own loggers. Just add a tag.
symfony.com/doc/current/reference/dic_tags.html#mo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question