-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: Add log file rotation support
An external log file rotation tool, such as `logrotate` will not work with an operating system such as Windows. From the Python documentation for `WatchedFileHandler` (which is used for log files in Salt): "This handler is not appropriate for use under Windows, because under Windows open log files cannot be moved or renamed - logging opens the files with exclusive locks - and so there is no need for such a handler. Furthermore, ST_INO is not supported under Windows; stat() always returns zero for this value." This also describes the problem with why an external utility such as `logrotate` will not work for Windows, because files cannot be renamed while in use, unlike on other operating systems, such as Linux. Due to the above, the strategy for this change is to use the `RotatingFileHandler` logger (when log file rotation is enabled) and to allow only one process to do the file logging. Previously on Windows, there was a file logger installed in the main process and another in the logging listener process. This change changes the architecture in the following way (on Windows only): - Added two new configuration options, `log_rotate_max_bytes` and `log_rotate_backup_count`. They both default to 0. When `log_rotate_max_bytes` is non-zero, the `RotatingFileHandler` will be used for file logging instead of the `WatchedFileHandler`. - The only process that does file logging is the logging listener process (if it exists) - When the logging listener process does not exist, only the main process does file logging. - When the logging listener process exists, the main process will now set up multiprocessing logging (which is the client to the logging listener). - Since the logging listener does logging for extended logging, console, and log file logging, do not use these types of logging in the main process when there is a logging listener. There is one observed caveat: when the log file is in use, and it is time to rollover (rename the file), the rollover will fail. This has been obversed when salt-call is running and has the `minion` log file open for its own logging uses while the salt-minion is trying to rollover. Luckily, it will recover and try to rollover again on the next log write, and if the file is no longer in use, it will succeed this time. Hence, having a log file open somewhere else will delay rollover until the file is closed. Signed-off-by: Sergey Kizunov <sergey.kizunov@ni.com>
- Loading branch information
Showing
4 changed files
with
173 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters