From d08425e17db2359ca1c9b30b38c5b8e36b283695 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Fri, 22 Jul 2022 15:09:52 +0300 Subject: [PATCH] Add logger for insight logs --- engine/apps/api/views/test_insight_logs.py | 3 ++- engine/settings/base.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/engine/apps/api/views/test_insight_logs.py b/engine/apps/api/views/test_insight_logs.py index ca3d5912..092536e6 100644 --- a/engine/apps/api/views/test_insight_logs.py +++ b/engine/apps/api/views/test_insight_logs.py @@ -7,6 +7,7 @@ from rest_framework.views import APIView from apps.auth_token.auth import PluginAuthentication logger = logging.getLogger(__name__) +insight_logger = logging.getLogger("insight_logger") class TestInsightLogsAPIView(APIView): @@ -27,6 +28,6 @@ class TestInsightLogsAPIView(APIView): insight_logs_enabled = org.id in org_id_to_enable_insight_logs.json_value if insight_logs_enabled: message = request.data.get("message", "hello world") - logger.info(f"insight_logs=true tenant_id={self.request.user.organization.stack_id} message={message}") + insight_logger.info(f"tenant_id={self.request.user.organization.stack_id} message={message}") return Response() return Response(status=418) diff --git a/engine/settings/base.py b/engine/settings/base.py index 515d1317..33e95a63 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -154,6 +154,7 @@ LOGGING = { "filters": {"request_id": {"()": "log_request_id.filters.RequestIDFilter"}}, "formatters": { "standard": {"format": "source=engine:app google_trace_id=%(request_id)s logger=%(name)s %(message)s"}, + "insight_logger": {"format": "insight_logs=true %(message)s"}, }, "handlers": { "console": { @@ -161,8 +162,17 @@ LOGGING = { "filters": ["request_id"], "formatter": "standard", }, + "insight_logger": { + "class": "logging.StreamHandler", + "formatter": "insight_logger", + }, }, "loggers": { + "insight_logger": { + "handlers": ["insight_logger"], + "level": "INFO", + "propagate": True, + }, "": { "handlers": ["console"], "level": "INFO",