Conversation
- Automatically prune log files older than log_retention_days (default 5 days) on startup - Enforce max_files limit (default 10) to prevent disk space exhaustion on small VPS/servers (fixes Duff89#274) - Enable zip compression for rotated log files in Loguru, reducing log disk usage by 90%+ - Add log_retention_days and log_max_files options to AvitoConfig and config.toml - Add unit tests in tests/test_log_cleanup.py
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Автоматическая очистка устаревших лог-файлов и сжатие логов (Fixes #274)
Реализовано решение проблемы переполнения постоянной памяти на серверах и VPS из-за накопления лог-файлов.
В чем была проблема (#274):
Ротация Loguru (
retention="5 days") срабатывает только в рамках одного непрерывного процесса при превышении размера файла (5 MB). При частых перезапусках парсера, сбоях или аварийных остановках старые логи прошлых сессий никогда не удалялись автоматически и занимали гигабайты памяти на диске.Что сделано:
utils/log_cleanup.py):clean_old_logs(), которая сканирует директорию логов при запуске приложения (parser_cls.pyиAvitoParser.py).log_retention_days(по умолчанию 5 дней).log_max_files(по умолчанию 10), удаляя самые старые при превышении.logger.add("logs/app.log")включен параметрcompression="zip". Текстовые логи сжимаются более чем на 90%, что практически сводит к нулю потребление дискового пространства архивными файлами.config.tomlиdto.py:log_retention_days = 5иlog_max_files = 10вAvitoConfig.tests/test_log_cleanup.py):