diff --git a/api/views.py b/api/views.py index 1deb5bd..c67286f 100644 --- a/api/views.py +++ b/api/views.py @@ -477,4 +477,4 @@ class BalanceViewSet(viewsets.ViewSet): description=request.data['description']) return Response(BalanceTransactionSerializer(balance_transaction).data) -# end region +# endregion diff --git a/core/management/commands/event_monitor.py b/core/management/commands/event_monitor.py index 58386d1..e41eb95 100644 --- a/core/management/commands/event_monitor.py +++ b/core/management/commands/event_monitor.py @@ -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): diff --git a/core/management/commands/process_invoice.py b/core/management/commands/process_invoice.py index ec2b417..17d3e5a 100644 --- a/core/management/commands/process_invoice.py +++ b/core/management/commands/process_invoice.py @@ -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]] = {} diff --git a/yuyu/settings.py b/yuyu/settings.py index 66baf93..09aebb0 100644 --- a/yuyu/settings.py +++ b/yuyu/settings.py @@ -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: