62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import os
|
|
import logging
|
|
import logging.config
|
|
from .local_storage import set_current_trace_id, get_current_trace_id
|
|
|
|
class TraceIDLogFilter(logging.Filter):
|
|
def filter(self, record):
|
|
trace_id = get_current_trace_id()
|
|
record.trace_id = trace_id
|
|
return True
|
|
|
|
LOG_ROOT = os.getenv("LOG_ROOT", "/home/tuanlv/workspace/02-KVU/sdsvkvu/logs")
|
|
|
|
LOGGER_CONFIG = {
|
|
"version": 1,
|
|
"formatters": {
|
|
"default": {
|
|
"format": "%(asctime)s - %(name)s - %(levelname)s - %(trace_id)s - %(message)s"
|
|
}
|
|
},
|
|
"filters": {
|
|
"trace_id": {
|
|
"()": TraceIDLogFilter
|
|
}
|
|
},
|
|
"handlers": {
|
|
'console': {
|
|
'class': 'logging.StreamHandler',
|
|
'formatter': 'default',
|
|
'filters': ['trace_id'],
|
|
},
|
|
"file_handler": {
|
|
"class": "logging.handlers.TimedRotatingFileHandler",
|
|
"filename": f"{LOG_ROOT}/sbt_idp_AI.log",
|
|
"level": "DEBUG",
|
|
"formatter": "default",
|
|
"filters": ["trace_id"],
|
|
"when": "midnight",
|
|
"interval": 1,
|
|
'backupCount': 10,
|
|
}
|
|
},
|
|
"loggers": {
|
|
"sdsvkvu": {
|
|
"level": "DEBUG",
|
|
"handlers": ["console", "file_handler"],
|
|
},
|
|
'': {
|
|
'handlers': ['console', 'file_handler'],
|
|
'level': 'INFO',
|
|
},
|
|
'django': {
|
|
'handlers': ['console', 'file_handler'],
|
|
'level': 'INFO',
|
|
},
|
|
'celery': {
|
|
'handlers': ['console', 'file_handler'],
|
|
'level': 'DEBUG',
|
|
},
|
|
}
|
|
}
|