Logging handler to send logs to your OpenSearch cluster with bulk SSL. Forked from https://github.com/logzio/logzio-python-handler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Roi Rav-Hon 5b6ca601d5 Added django documentations 8 years ago
logzio Better handle logz.io responses, and drain to file in case of an unrecoverable error 8 years ago
LICENSE License update before release 8 years ago
README.md Added django documentations 8 years ago
setup.cfg.py Added readme and pipy related files 8 years ago
setup.py License update before release 8 years ago

README.md

Logz.io python handler

Python handler that sends logs in bulk over https to logz.io. The handler use an internal buffer, and you can choose the drain timeout, and the number of messages to hold in queue before drain. Everything is working in threads, and they would exit after completing draining all the logs if the main program exits.

This is BETA. We currently use this handler internally. We will provide tests soon.

Installation

pip install logzio-python-handler

Python configuration

Config File

[handlers]
keys=LogzioHandler

[handler_LogzioHandler]
class=logzio.handler.LogzioHandler
formatter=jsonFormat
args=('token', 10, 20)

[formatters]
keys=jsonFormat

[loggers]
keys=root

[logger_root]
handlers=LogzioHandler
level=INFO

[formatter_jsonFormat]
format={ "loggerName":"%(name)s", "functionName":"%(funcName)s", "lineNo":"%(lineno)d", "levelName":"%(levelname)s", "message":"%(message)s"}

args=() arguments, by order

  • Your logz.io token
  • Number of logs to keep in buffer before draining
  • Time to wait before draining, regardless of the previouse setting
  • Log type, for searching in logz.io (defaults to "python")

Code Example

import logging
import logging.config

# Say i have saved my configuration under ./myconf.conf
logging.config.fileConfig('myconf.conf')
logger = logging.getLogger('superAwesomeLogzioLogger')

logger.info('Test log')
logger.warn('Warning')

try:
    1/0
except:
    logger.exception("Supporting exceptions too!")

Django configuration

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'json': {
            'format': '{ "loggerName":"%(name)s", "functionName":"%(funcName)s", "lineNo":"%(lineno)d", "levelName":"%(levelname)s", "message":"%(message)s"}'
        }
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'level': 'DEBUG',
            'formatter': 'verbose'
        },
        'logzio': {
            'class': 'logzio.handler.LogzioHandler',
            'level': 'INFO',
            'formatter': 'json',
            'token': 'token',
            'logs_drain_count': 10,
            'logs_drain_timeout': 5,
            'logzio_type': "django"
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console', ],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO')
        },
        'appname': {
            'handlers': ['console', 'logzio'],
            'level': 'INFO'
        }
    }
}

Change

  • token - Your logzio token
  • logs_drain_count - Number of logs to keep in buffer before draining
  • logs_drain_timeout - Time to wait before draining, regardless of the previouse setting
  • logzio_type - Log type, for searching in logz.io (defaults to "python")
  • appname - Your django app