diff --git a/utils/logs/handlers.py b/utils/logs/handlers.py index a647255..284e6a4 100644 --- a/utils/logs/handlers.py +++ b/utils/logs/handlers.py @@ -27,7 +27,7 @@ class LokiHandler(logging.Handler): try: payload = self.formatter.format(record) - _push_message( + self._push_message( self._url, json=payload, timeout=self._timeout, auth=self._auth ) except requests.exceptions.ReadTimeout: @@ -41,7 +41,6 @@ class LokiHandler(logging.Handler): self.formatter = fmt def _push_message(self, *args, **kwargs): - print('hehe') if self._mode == "sync": return _push_message(*args, **kwargs) diff --git a/wallet/settings.py b/wallet/settings.py index 31cabab..8c57511 100644 --- a/wallet/settings.py +++ b/wallet/settings.py @@ -262,4 +262,42 @@ CACHES = { } } +LOKI_BASE_PUBLIC_URL = config('LOKI_BASE_PUBLIC_URL', default=None, cast=str) + + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'loki': { + 'class': 'utils.logs.LokiFormatter', # required + }, + }, + + 'handlers': { + 'loki': { + 'level': 'DEBUG', # Log level. Required + 'class': 'utils.logs.LokiHandler', # Required + 'formatter': 'loki', # Loki formatter. Required + 'timeout': 1, # Post request timeout, default is 0.5. Optional + 'url': f'{LOKI_BASE_PUBLIC_URL}/loki/api/v1/push', # Loki url. Defaults to localhost. Optional. + # 'auth': ("user", "password"), # Basic auth to authenticate with loki. Default is None (i.e. no auth). Optional + 'tags': {"app": "wallet"}, # Tags / Labels to attach to the log. Optional, but strongly encoraged to use. + 'mode': 'thread', # Push mode. Can be 'sync' or 'thread'. Sync is blocking, thread is non-blocking. Defaults to sync. Optional. + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + # 'formatter': 'verbose', + }, + }, + 'loggers': { + '': { + 'handlers': ['console', 'loki'], + 'level': 'INFO', + 'propagate': True, + }, + }, +} + ALLOWED_NEGATIVE_BALANCE_APPLICATIONS = config('ALLOWED_NEGATIVE_BALANCE_APPLICATIONS', cast=lambda v: [s.strip() for s in v.split(',')]) \ No newline at end of file