-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add logging setting #147
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
base: main
Are you sure you want to change the base?
Conversation
maxjamchuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отличная идея добавить единый конфиг логирования. Перед мержем необходимо исправить замечания с лейблами CAUTION и WARNING (disable_existing_loggers=True). Остальные комментарии — рекомендательные.
app/settings.py
Outdated
| # Logging | ||
| LOGGING = { | ||
| "version": 1, | ||
| "disable_existing_loggers": True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
"disable_existing_loggers": True — это часто ломает/глушит логи Django и сторонних библиотек (в т.ч. django.request, django.server), потому что “существующие логгеры” отключаются, если их явно не описать в конфиге.
Рекомендация: либо поставить False, либо добавить явные секции loggers для django, django.request, etc., чтобы не потерять важные сообщения/стектрейсы.
| }, | ||
| "handlers": { | ||
| "console": { | ||
| "class": "logging.StreamHandler", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
handler logging.StreamHandler по умолчанию пишет в stderr. В контейнерах обычно ожидают stdout. Можно явно задать stream: "ext://sys.stdout" (или оставить как есть, если в проекте принято stderr).
| "disable_existing_loggers": True, | ||
| "formatters": { | ||
| "default": { | ||
| "format": "[{asctime}] #{levelname:8} {name}:{lineno}:{funcName} - {message}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
форматтер сейчас очень “шумный” ({lineno}:{funcName}) и при DEBUG=True будет много логов. Это ок для дев-режима, но в проде обычно выбирают уровень INFO (а не WARNING), плюс отдельные правила для django.request (например, 4xx/5xx). Можно подумать над более “продуктовым” дефолтом уровня/логгеров.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
пересмотреть disable_existing_loggers=True, чтобы не потерять системные логи Django/библиотек.
Добавлена настройка для вывода логов в консоль.