-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log rotate #4032
Log rotate #4032
Conversation
When the log file reaches 32 MB, it's automatically compressed using gzip and moved to the log_archive directory of the server data directory. This is rather costly (200-400ms of CPU time on my i7-7700HQ), but since 32 MB log files shouldn't be achieved very often, this overhead shouldn't be an issue. 32 MB was chosen because this is still handleable by Windows Notepad (in case a user happens to double click we don't want their PC to melt down) and sufficiently small enough that compression won't block the logger for minutes at a time, but large enough to minimize disk wastage (partial sector allocations). I do have some concerns about logs possibly not getting written if forced termination occurs (e.g. segfault). While these were already potential problems to begin with, a 0.3sec window for a fault to occur in means that a larger number of messages might disappear if a termination occurs.
Blocked until pmmp/ext-pmmpthread#42 is resolved |
pmmp/ext-pmmpthread@b2b6100 should resolve the performance issue blocking this |
we really need a logger context inside this thread ...
Another problem I hadn't foreseen: If a user with a very large log file (e.g. 50 GB) loads this code in their server, the We probably need an extra thread to solve this. |
I'm thinking this would be OK if we were to get rid of the compression step. If we have the server move old logs to a new location and release them, external systems can handle cleaning them up, compressing them, or whatever else. The only thing we really need to do is release handles to the file(s) containing the archival logs, so that they can be processed by other tools without stopping the server. |
we let the user decide what to do with these files instead
…s exceeded on shutdown
fstat() is quite costly, so we don't want to spam it in a loop.
Introduction
server.log
is not rotated by default and grows unmanageably large, to the point where it's so huge that it's not possible to read it with any standard text editor anymore.This PR implements automatic log rotation.
server.log
reaches 32MB in size, it's moved to thelog_archive
folder of the server's data folder.server.2024-03-15T15.26.24.0.log
This has several benefits:
log_archive/
can be safely deleted and/or modified while the server is runningWhy not automatically compress the files?
The original version of this PR did exactly that, but it created various problems, such as the possibility of the logger stalling while compressing large log files, disk running out of space, etc.
If you want to automatically compress or clean up the log files yourself, I suggest an external cron job or disk watcher.
Relevant issues
Closes #4029.
Changes
Behavioural changes
Described above.
Tests
This can be seen in action using the following script. It will generate 4 log files in
$PWD/testlogsarchive
.