django python上传日志到splunk

官方文档 https://github.com/zach-taylor/splunk_handler

need https://github.com/madzak/python-json-logger

pip3 install  splunk_handler

pip install python-json-logger

# Splunk settings
SPLUNK_HOST = YOUR_SPLUNK_HOST
SPLUNK_PORT = YOUR_SPLUNK_PORT
SPLUNK_TOKEN = YOUR_SPLUNK_TOKEN
SPLUNK_INDEX = YOUR_SPLUNK_INDEX

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
            'format': '%(asctime)s %(created)f %(exc_info)s %(filename)s %(funcName)s %(levelname)s %(levelno)s %(lineno)d %(module)s %(message)s %(pathname)s %(process)s %(processName)s %(relativeCreated)d %(thread)s %(threadName)s'
        }
    },
    'handlers': {
        'splunk': {
            'level': 'DEBUG',
            'class': 'splunk_handler.SplunkHandler',
            'formatter': 'json',
            'host': SPLUNK_HOST,
            'port': SPLUNK_PORT,
            'token': SPLUNK_TOKEN,
            'index': SPLUNK_INDEX,
            'sourcetype': 'json',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
        }
    },
    'loggers': {
        '': {
            'handlers': ['console', 'splunk'],
            'level': 'DEBUG'
        }
    }
}

  

posted @ 2020-05-15 11:32  shmily3929  阅读(312)  评论(0编辑  收藏  举报