📜 ⬆️ ⬇️

log4php or something else?

Here I am faced with the fact that I need to write logs to the same file from many application threads (no, it doesn't fit into the database)

Having considered the options with flock - I realized that the time for another thread to receive a lock for writing to the file is pretty long - refused.

Found the project log4php - this is the port on php from the project log4j
')

Prefixed it - removed all sorts of bugs - put it on production. And it turned out that with a large load (about 7-10k bits per second), log4php does not perform its multi-threaded write to the file (it skips the logs, then writes them into a mix from different streams). Moreover, when filling a file up to the limit, log4php begins to do similarly to logrotate (the log file is renamed to log.txt.1 and the current log is reset to zero.) - which also fails - it blows old files off - nulls them due to what at the time of renaming ( when log.txt has already changed the name) other threads write to log.txt and then it is renamed again to log.txt.1 and log.txt.1 is roughly demolished - and there the necessary logs are :)

Therefore, the question - what can be used for multi-threaded logging - is fast and necessarily multi-threaded.

Source: https://habr.com/ru/post/29765/


All Articles