App logs kept forever: nightly gzip on 249 (LOG_FILE_ROTATION=external), hourly pull to 247 via a forced-command key, health warns if the archive stops

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 17:54:05 +03:30
parent f4831e93a7
commit 3559c43902
10 changed files with 180 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
import os
import tempfile
from django.test import SimpleTestCase, override_settings
from config import health
class AppLogSizeWarningTests(SimpleTestCase):
"""با چرخشِ بیرونی برنامه app.log را پاک نمی‌کند؛ اگر آرشیوِ شبانه بخوابد /api/health باید بگوید."""
def _with_log(self, size, rotation):
d = tempfile.mkdtemp()
with open(os.path.join(d, 'app.log'), 'wb') as f:
f.truncate(size)
with override_settings(LOG_DIR=d, LOG_FILE_ROTATION=rotation):
return health._app_log_warnings()
def test_big_log_with_external_rotation_warns(self):
self.assertEqual(len(self._with_log(health.APP_LOG_MAX_BYTES + 1, 'external')), 1)
def test_small_log_is_quiet(self):
self.assertEqual(self._with_log(1024, 'external'), [])
def test_size_rotation_never_warns(self):
self.assertEqual(self._with_log(health.APP_LOG_MAX_BYTES + 1, 'size'), [])