H
H
Horder2021-01-26 10:44:25
PHP
Horder, 2021-01-26 10:44:25

How to solve the leak of logs when writing them?

There is a project on Symfony 3.4. Monolog (StreamHandler) is used as a logger and Stackify is additionally integrated.

There is an algorithm, at each step (let's say there are only 4 of them) of which logs are necessarily created (either success or error). The problem is that after passing through the algorithm, several outcomes are possible:
1. There are all 4 entries in the logs (normal state);
2. There is only the first part of the logs (for example, 1 and 2 entries);
3. There is only the last entry (4). The interesting thing is that there is no way they can be recorded without going through the previous steps.
4. There are no logs at all.

Is it possible that when the server is loaded, the log file is mutually blocked by threads and as a result, no records will be written, in the future the thread will fall off on a timeout?

There was a proposal to transfer the logs to RabbitMQ with further processing by a third-party subscriber. In this case, will there be additional excessive load on the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2021-01-26
@neuotq

It's hard to say without more detailed logic and code. You most likely have an error somewhere. Writing to Monolog is in append mode fopen + a , which means (on a POSIX compliant OS):

O_APPEND and O_CREAT
O_APPEND Перед каждой записью помещает указатель файла в конец
файла. Иными словами, все операции записи будут
происходить в конец файла.
O_CREAT Создает файл, если он не существует.

Therefore, in general, there should be no problems in Linux (roughly speaking), since fwrite (with fopen + a) will work in atomic mode (and there is no need to lock the file), only the order of the lines is not guaranteed.
And I didn’t quite understand about RabbitMQ. Well, ok, you sent a message somewhere, but then you still need to write it down again?
As for the load, this is secondary here, you need to proceed from the logic of the application, well, RabbitMQ still works quickly, it will not be a bottleneck in comparison with writing to a file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question