Add logger for insight logs

This commit is contained in:
Ildar Iskhakov 2022-07-22 15:09:52 +03:00
parent 4a0dbe674c
commit d08425e17d
2 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -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",