Skip to content

Commit

Permalink
Merge pull request #52 from Build-Squad/GEN-96-Enable-Logging
Browse files Browse the repository at this point in the history
Gen 96 enable logging
  • Loading branch information
muditmahajan authored Dec 26, 2023
2 parents 62a07d1 + b7a1082 commit cdc87f8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ src/api/marketplace/.idea/marketplace.iml
src/api/marketplace/.idea/misc.xml
src/api/marketplace/.idea/vcs.xml
src/api/marketplace/.idea/workspace.xml
src/api/marketplace/marketplace/logs/
7 changes: 7 additions & 0 deletions src/api/marketplace/marketplace/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from rest_framework.response import Response
from rest_framework import status
from django.core.mail import send_mail
# from .logger import custom_logger

# logger = custom_logger()
import logging
logger = logging.getLogger(__name__)


# JWT cookie related operations
Expand Down Expand Up @@ -106,6 +111,7 @@ def getPageInfo(self):


def handleServerException(e):
logger.error(e)
return Response({
'isSuccess': False,
'data': None,
Expand All @@ -115,6 +121,7 @@ def handleServerException(e):


def handleBadRequest(e):
logger.error(e)
return Response({
'isSuccess': False,
'data': None,
Expand Down
50 changes: 50 additions & 0 deletions src/api/marketplace/marketplace/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MARKETPLACE_APP_DIR = os.path.join(BASE_DIR, 'marketplace')
LOGGING_DIR = os.path.join(MARKETPLACE_APP_DIR, 'logs')

if not os.path.exists(LOGGING_DIR):
os.makedirs(LOGGING_DIR)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
Expand All @@ -30,6 +34,52 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'django': {
'()': 'django.utils.log.ServerFormatter',
'format': '[{server_time}] {levelname} {message}',
'style': '{',
},
'simpleRe': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
},
"handlers": {
"console": {
'level': 'INFO',
"class": "logging.StreamHandler",
"formatter": "django",
},
"file": {
"level": "ERROR",
'class': 'logging.handlers.TimedRotatingFileHandler',
"filename": os.path.join(LOGGING_DIR, "error.log"),
"formatter": "simpleRe",
},
},
"loggers": {
"django": {
"handlers": ["file"],
"level": "INFO",
"propagate": True,
},
"django.request": {
"handlers": ["file"],
"level": "ERROR",
"propagate": True,
},
"": {
"handlers": ["file"],
"level": "ERROR",
"propagate": True,
},
}
}

ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
Expand Down

0 comments on commit cdc87f8

Please sign in to comment.