From 476762c7c24d6c4dc40eb73cc55dc7e6e79e154b Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Mon, 18 Nov 2024 15:08:02 +0100 Subject: [PATCH 1/3] :loud_sound: add celery logging --- open_api_framework/conf/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/open_api_framework/conf/base.py b/open_api_framework/conf/base.py index 2191732..12dc72b 100644 --- a/open_api_framework/conf/base.py +++ b/open_api_framework/conf/base.py @@ -507,6 +507,11 @@ "level": "DEBUG", "propagate": True, }, + "celery": { + "handlers": logging_root_handlers, + "level": LOG_LEVEL, + "propagate": True, + }, }, } From ce1ff8037a5e3a858259692b19ec8fe4f9d3c65e Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Fri, 22 Nov 2024 12:56:07 +0100 Subject: [PATCH 2/3] :loud_sound: create separate logger for celery --- open_api_framework/conf/base.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/open_api_framework/conf/base.py b/open_api_framework/conf/base.py index 12dc72b..c326369 100644 --- a/open_api_framework/conf/base.py +++ b/open_api_framework/conf/base.py @@ -377,6 +377,13 @@ RuntimeWarning, ) +CELERY_LOGLEVEL = config( + "CELERY_LOGLEVEL", + default="INFO", + help_text="control the verbosity of logging output for celery, separate from ``LOG_LEVEL``." + " Available values are ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO`` and ``DEBUG``", +) + LOGGING_DIR = Path(BASE_DIR) / "log" logging_root_handlers = ["console"] if LOG_STDOUT else ["project"] @@ -415,6 +422,19 @@ "class": "logging.StreamHandler", "formatter": "db", }, + "console_celery": { + "level": CELERY_LOGLEVEL, + "class": "logging.StreamHandler", + "formatter": "timestamped", + }, + "celery_file": { + "level": CELERY_LOGLEVEL, + "class": "logging.handlers.RotatingFileHandler", + "filename": Path(LOGGING_DIR) / "celery.log", + "formatter": "verbose", + "maxBytes": 1024 * 1024 * 10, # 10 MB + "backupCount": 10, + }, "django": { "level": LOG_LEVEL, "class": "logging.handlers.RotatingFileHandler", @@ -508,8 +528,8 @@ "propagate": True, }, "celery": { - "handlers": logging_root_handlers, - "level": LOG_LEVEL, + "handlers": ["console_celery"] if LOG_STDOUT else ["celery_file"], + "level": CELERY_LOGLEVEL, "propagate": True, }, }, From 66d50135cb565fc90591caa6198fb259498c516a Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Mon, 9 Dec 2024 12:01:56 +0100 Subject: [PATCH 3/3] :wrench: make LOG_STDOUT true by default --- open_api_framework/conf/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/open_api_framework/conf/base.py b/open_api_framework/conf/base.py index c326369..f733f09 100644 --- a/open_api_framework/conf/base.py +++ b/open_api_framework/conf/base.py @@ -350,7 +350,7 @@ # LOGGING # LOG_STDOUT = config( - "LOG_STDOUT", default=False, help_text="whether to log to stdout or not" + "LOG_STDOUT", default=True, help_text="whether to log to stdout or not" ) LOG_LEVEL = config( "LOG_LEVEL", @@ -380,7 +380,7 @@ CELERY_LOGLEVEL = config( "CELERY_LOGLEVEL", default="INFO", - help_text="control the verbosity of logging output for celery, separate from ``LOG_LEVEL``." + help_text="control the verbosity of logging output for celery, independent of ``LOG_LEVEL``." " Available values are ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO`` and ``DEBUG``", ) @@ -422,7 +422,7 @@ "class": "logging.StreamHandler", "formatter": "db", }, - "console_celery": { + "celery_console": { "level": CELERY_LOGLEVEL, "class": "logging.StreamHandler", "formatter": "timestamped", @@ -528,7 +528,7 @@ "propagate": True, }, "celery": { - "handlers": ["console_celery"] if LOG_STDOUT else ["celery_file"], + "handlers": ["celery_console"] if LOG_STDOUT else ["celery_file"], "level": CELERY_LOGLEVEL, "propagate": True, },