зеркало из https://github.com/mozilla/pontoon.git
Add ability to log to a file (#3260)
Co-authored-by: Matjaž Horvat <matjaz.horvat@gmail.com>
This commit is contained in:
Родитель
e31fb16a44
Коммит
185a7e0b05
|
@ -26,6 +26,7 @@ venv
|
|||
/media/
|
||||
.cache/
|
||||
coverage/
|
||||
*.log
|
||||
|
||||
# Docker
|
||||
.server-build
|
||||
|
|
|
@ -10,6 +10,8 @@ FXA_SECRET_KEY=e43fd751ca5687d28288098e3e9b1294792ed9954008388e39b1cdaac0a1ebd6
|
|||
FXA_OAUTH_ENDPOINT=https://oauth.stage.mozaws.net/v1
|
||||
FXA_PROFILE_ENDPOINT=https://profile.stage.mozaws.net/v1
|
||||
|
||||
LOG_TO_FILE=False
|
||||
|
||||
EMAIL_CONSENT_ENABLED = False
|
||||
EMAIL_CONSENT_TITLE = Let’s keep in touch
|
||||
EMAIL_CONSENT_MAIN_TEXT = Want to stay up to date and informed about all localization matters at Mozilla? Just hit the button below to get the latest updates, announcements about new Pontoon features, invitations to contributor events and more. We won’t spam you — promise!
|
||||
|
|
|
@ -171,6 +171,10 @@ you create:
|
|||
Optional. Set your `Google Cloud AutoML Translation`_ model ID to use custom machine
|
||||
translation engine by Google.
|
||||
|
||||
``LOG_TO_FILE``
|
||||
Optional. Enables logging to a file (default: ``False``).
|
||||
This is useful for retaining log data for later analysis or troubleshooting.
|
||||
|
||||
``MAINTENANCE_PAGE_URL``
|
||||
Optional. URL to the page displayed to your users when the application is placed
|
||||
in the maintenance state. See `Heroku Reference`_ for more information.
|
||||
|
|
|
@ -769,6 +769,32 @@ PASSWORD_HASHERS = (
|
|||
)
|
||||
|
||||
# Logging
|
||||
# Get environment variables
|
||||
LOG_TO_FILE = os.getenv("LOG_TO_FILE", "False") == "True"
|
||||
|
||||
# Ensure the logs directory exists
|
||||
if LOG_TO_FILE:
|
||||
log_dir = path("logs")
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
|
||||
# Define file handlers
|
||||
django_file_handler = {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": path("logs", "django_debug.log"),
|
||||
"maxBytes": 1024 * 1024 * 2, # 2 MB
|
||||
"backupCount": 3,
|
||||
"formatter": "verbose",
|
||||
}
|
||||
|
||||
pontoon_file_handler = {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": path("logs", "pontoon_debug.log"),
|
||||
"maxBytes": 1024 * 1024 * 2, # 2 MB
|
||||
"backupCount": 3,
|
||||
"formatter": "verbose",
|
||||
}
|
||||
|
||||
# Define logging configuration
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
|
@ -785,6 +811,13 @@ LOGGING = {
|
|||
},
|
||||
}
|
||||
|
||||
# Adding file handlers if logging to file is enabled
|
||||
if LOG_TO_FILE:
|
||||
LOGGING["handlers"]["django_file"] = django_file_handler
|
||||
LOGGING["handlers"]["pontoon_file"] = pontoon_file_handler
|
||||
LOGGING["loggers"]["django"]["handlers"].append("django_file")
|
||||
LOGGING["loggers"]["pontoon"]["handlers"].append("pontoon_file")
|
||||
|
||||
if DEBUG:
|
||||
LOGGING["handlers"]["console"]["formatter"] = "verbose"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче