Skip to content

Commit

Permalink
added attendance logger to db
Browse files Browse the repository at this point in the history
  • Loading branch information
Diwakar-Gupta committed Feb 15, 2024
1 parent 3cfc742 commit 37fa571
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion attendance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
from utils.validate_location import is_in_class
from utils.pushNotification import pushNotification

import logging

db_logger = logging.getLogger("db")


def psp(request, mail_prefix):
response = []
Expand Down Expand Up @@ -321,7 +325,7 @@ def mark_attendance_subject(request, pk):
},
status=403,
)

db_logger.info(f"Mark Attendance: {request.user.email}: {request.body}")
curr_class = SubjectClass.objects.get(pk=pk)
if curr_class is None:
return JsonResponse({}, status=400)
Expand Down
26 changes: 26 additions & 0 deletions mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_db_logger",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -162,3 +163,28 @@
"LOCATION": "unique-snowflake",
}
}

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s"
},
"simple": {"format": "%(levelname)s %(asctime)s %(message)s"},
},
"handlers": {
"db_log": {
"level": "DEBUG",
"class": "django_db_logger.db_log_handler.DatabaseLogHandler",
},
},
"loggers": {
"db": {"handlers": ["db_log"], "level": "DEBUG"},
"django.request": { # logging 500 errors to database
"handlers": ["db_log"],
"level": "ERROR",
"propagate": False,
},
},
}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ charset-normalizer==3.3.2
cryptography==41.0.7
dj-database-url==1.2.0
Django==4.2.8
django-db-logger==0.1.13
django-enumfields==2.1.1
firebase-admin==6.2.0
google-api-core==2.14.0
Expand Down Expand Up @@ -36,6 +37,7 @@ PyJWT==2.8.0
pyparsing==3.1.1
requests==2.31.0
rsa==4.9
six==1.16.0
sqlparse==0.4.4
tqdm==4.66.1
typing_extensions==4.8.0
Expand Down

0 comments on commit 37fa571

Please sign in to comment.