improve logging (#2)
This commit is contained in:
parent
c2a6745b00
commit
acb95b379d
4 changed files with 40 additions and 5 deletions
|
@ -477,4 +477,4 @@ class BalanceViewSet(viewsets.ViewSet):
|
|||
description=request.data['description'])
|
||||
return Response(BalanceTransactionSerializer(balance_transaction).data)
|
||||
|
||||
# end region
|
||||
# endregion
|
||||
|
|
|
@ -12,7 +12,7 @@ from django.core.management.base import BaseCommand
|
|||
|
||||
from core.event_endpoint import EventEndpoint
|
||||
|
||||
LOG = logging.getLogger("yuyu_notification")
|
||||
LOG = logging.getLogger("yuyu")
|
||||
|
||||
|
||||
class SignalExit(SystemExit):
|
||||
|
|
|
@ -12,16 +12,17 @@ from core.utils.dynamic_setting import get_dynamic_setting, BILLING_ENABLED, INV
|
|||
COMPANY_ADDRESS, INVOICE_AUTO_DEDUCT_BALANCE
|
||||
from yuyu import settings
|
||||
|
||||
LOG = logging.getLogger("yuyu_new_invoice")
|
||||
LOG = logging.getLogger("yuyu")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Yuyu New Invoice'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Processing Invoice")
|
||||
LOG.info("Processing Invoice")
|
||||
try:
|
||||
if not get_dynamic_setting(BILLING_ENABLED):
|
||||
LOG.info("Billing not activated")
|
||||
return
|
||||
|
||||
self.close_date = timezone.now()
|
||||
|
@ -31,13 +32,15 @@ class Command(BaseCommand):
|
|||
for active_invoice in active_invoices:
|
||||
self.close_active_invoice(active_invoice)
|
||||
except Exception:
|
||||
LOG.exception("Error Processing Invoice")
|
||||
send_notification(
|
||||
project=None,
|
||||
title='[Error] Error when processing Invoice',
|
||||
short_description=f'There is an error when Processing Invoice',
|
||||
content=f'There is an error when handling Processing Invoice \n {traceback.format_exc()}',
|
||||
)
|
||||
print("Processing Done")
|
||||
|
||||
LOG.info("Processing Invoice Done")
|
||||
|
||||
def close_active_invoice(self, active_invoice: Invoice):
|
||||
active_components_map: Dict[str, Iterable[InvoiceComponentMixin]] = {}
|
||||
|
|
|
@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
|
|||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
@ -132,15 +134,45 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'simple': {
|
||||
'format': '{levelname} {asctime} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
'file': {
|
||||
'class': 'logging.handlers.TimedRotatingFileHandler',
|
||||
'filename': os.path.join(BASE_DIR, 'logs/django_log.log'),
|
||||
'when': 'D',
|
||||
'formatter': 'simple'
|
||||
},
|
||||
'yuyu_file': {
|
||||
'class': 'logging.handlers.TimedRotatingFileHandler',
|
||||
'filename': os.path.join(BASE_DIR, 'logs/yuyu_log.log'),
|
||||
'when': 'D',
|
||||
'formatter': 'simple'
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['file', 'console'],
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
|
||||
'propagate': False,
|
||||
},
|
||||
'yuyu': {
|
||||
'handlers': ['yuyu_file', 'console'],
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue