From 79a34c9b55b761d0cf7866dfeb052097e2b2ba54 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 5 Nov 2024 03:43:18 +0100 Subject: [PATCH] logger: always do traceback when DEBUG var is True related to #13 --- evidence/management/commands/up_snapshots.py | 4 +--- utils/logger.py | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/evidence/management/commands/up_snapshots.py b/evidence/management/commands/up_snapshots.py index 69ac134..c987d76 100644 --- a/evidence/management/commands/up_snapshots.py +++ b/evidence/management/commands/up_snapshots.py @@ -58,8 +58,6 @@ class Command(BaseCommand): self.devices.append(Build(s, self.user)) move_json(p, self.user.institution.name) except Exception as err: - if settings.DEBUG: - logger.exception("%s", err) snapshot_id = s.get("uuid", "") - txt = "It is not possible to parse snapshot: %s" + txt = "Could not parse snapshot: %s" logger.error(txt, snapshot_id) diff --git a/utils/logger.py b/utils/logger.py index b97fe2e..df85e7e 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -1,4 +1,5 @@ import logging +from django.conf import settings # Colors RED = "\033[91m" @@ -24,6 +25,11 @@ class CustomFormatter(logging.Formatter): record.msg = self.highlight_args(record.msg, record.args, color) record.args = () + # provide trace when DEBUG config + if settings.DEBUG: + import traceback + print(traceback.format_exc()) + return super().format(record) def highlight_args(self, message, args, color):