logger
This commit is contained in:
parent
d67f4f6069
commit
3443cba7bd
2 changed files with 15 additions and 31 deletions
|
|
@ -250,20 +250,14 @@ CACHES = {
|
|||
}
|
||||
}
|
||||
|
||||
LOKI_BASE_PUBLIC_URL = config('LOKI_BASE_PUBLIC_URL', default=None, cast=str)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
# 'verbose': {
|
||||
# 'format': '{levelname} AT: {asctime} LINE: {lineno} LOGGER: {name} FILE: {pathname} MESSAGE: {message}',
|
||||
# 'style': '{',
|
||||
# },
|
||||
# 'simple': {
|
||||
# 'format': '{levelname} {message}',
|
||||
# 'style': '{',
|
||||
# },
|
||||
'loki': {
|
||||
'class': "utils.logs.LokiFormatter", # required
|
||||
'class': 'utils.logs.LokiFormatter', # required
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -273,32 +267,23 @@ LOGGING = {
|
|||
'class': 'utils.logs.LokiHandler', # Required
|
||||
'formatter': 'loki', # Loki formatter. Required
|
||||
'timeout': 1, # Post request timeout, default is 0.5. Optional
|
||||
'url': 'https://loki.winsoo.ir/loki/api/v1/push', # Loki url. Defaults to localhost. 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": "promotions", "env": "production"},
|
||||
# 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.
|
||||
'tags': {"app": "promotions", "env": "production"}, # 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.
|
||||
},
|
||||
# 'file': {
|
||||
# 'level': 'DEBUG',
|
||||
# 'class': 'logging.handlers.TimedRotatingFileHandler',
|
||||
# 'filename': 'logs/app.log',
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
# 'formatter': 'verbose',
|
||||
# "when": 'D',
|
||||
# "backupCount": 5,
|
||||
# },
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['loki'],
|
||||
'': {
|
||||
'handlers': ['console', 'loki'],
|
||||
'level': 'INFO',
|
||||
'propagate': True,
|
||||
},
|
||||
# 'root': {
|
||||
# 'handlers': ['file'],
|
||||
# 'level': 'DEBUG',
|
||||
# 'propagate': True,
|
||||
# },
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue