Skip to content

Commit

Permalink
feat: added log for exceptions
Browse files Browse the repository at this point in the history
feat: get logging configuration from environment

refactor: removed unnecessary characters from log message
  • Loading branch information
Tiago-da-silva23 authored and jamoqs committed Dec 12, 2023
1 parent e94a266 commit 45ce617
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/util/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import logging
from datetime import datetime

from rest_framework.views import exception_handler


Expand All @@ -9,4 +12,7 @@ def custom_exception_handler(exc, context):
response.data = data
response.content_type = "application/json"

logging.getLogger("nau_financial_manager").error(
f"time:{datetime.now()}, error: {response.data}, exc: '{exc}', context: {context}"
)
return response
31 changes: 31 additions & 0 deletions nau_financial_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
import codecs
import copy
import logging.config
import os
from pathlib import Path

Expand Down Expand Up @@ -217,6 +218,36 @@ def get_env_setting(env_variable, default=None):
},
]


LOGGING = CONFIG.get(
"LOGGING",
{
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"level": "ERROR",
"class": "logging.StreamHandler",
},
},
"loggers": {
"django": {
"handlers": ["console"],
"level": "ERROR",
"propagate": True,
},
"nau_financial_manager": {
"handlers": ["console"],
"level": "ERROR",
"propagate": True,
},
},
},
)

LOGGING_CONFIG = None
logging.config.dictConfig(LOGGING)

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"
Expand Down

0 comments on commit 45ce617

Please sign in to comment.