Univention Bugzilla – Bug 56048
[Kelvin] fix log rotation | http.log - entries from the same date appear in different log files
Last modified: 2024-02-15 18:13:53 CET
The rotation of the `http.log` behaves in a weird way. Entries from the same date appear in different "old" logs. Example: ``` DEV root@ucs-001:/var/log/univention/ucsschool-kelvin-rest-api# ls -lrt [...] -rw------- 1 root root 25501 Mai 7 02:00 http.log.2023-05-06 -rw------- 1 root root 43403 Mai 9 02:00 http.log.2023-05-07 -rw------- 1 root root 365887 Mai 9 08:25 ucs-school-validation.log.2023-05-05 -rw------- 1 root root 590863 Mai 9 10:43 http.log.2023-05-08 -rw------- 1 root root 5515993 Mai 9 12:33 ucs-school-validation.log -rw-r----- 1 root root 305397697 Mai 9 12:36 opa.log -rw------- 1 root root 28963364 Mai 9 12:36 http.log DEV root@ucs-001:/var/log/univention/ucsschool-kelvin-rest-api# grep -c 2023-05-09 * http.log:123443 http.log.2023-05-07:33 http.log.2023-05-08:3254 ```
Fix suggestion: Follow the App Centers example in #55610 and 1. install a logrotate configuration in the host using UCRV without a service restart 2. use logging.handlers.WatchedFileHandler (https://devdocs.io/python~3.11/library/logging.handlers#logging.handlers.WatchedFileHandler) inside Docker container. From the docs: emit(): Outputs the record to the file, but first calls reopenIfNeeded() to reopen the file if it has changed. reopenIfNeeded(): Checks to see if the file has changed. If it has, the existing stream is flushed and closed and the file opened again, typically as a precursor to outputting the record to the file. So renaming the logfile (from the host) leads to the Python process - the next time it wants to write a message (!) - flushing its buffers to the renamed file and then creating a new file for the new message. If the renamed file is not compressed immediately there should be no data loss. --- If this fixes the logrotation issue for Kelvin, apply this fix also to all other UCS@school Python Docker apps like the UCS@school APIs app and the ID-Connector.