This commit is contained in:
Sayyid Hamid Mahdavi 2025-12-09 10:13:13 +03:30
parent a9935fe72c
commit 587a0d106b
2 changed files with 39 additions and 2 deletions

View file

@ -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)

View file

@ -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(',')])