Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Latest commit

 

History

History
62 lines (49 loc) · 1.3 KB

README.md

File metadata and controls

62 lines (49 loc) · 1.3 KB

datadoglog

Python logging handlers for sending logs to Datadog

Installation

to requirements.txt add

-e git+https://github.com/gadventures/[email protected]#egg=datadoglog

Usage

This package uses the QueueHandler logger, so you need to start the logger thread and give it a Queue.

import atexit
from queue import Queue

from datadoglog import start_datadog_logger

queue = Queue()
stop_logger = start_datadog_logger(queue)
atexit.register(stop_logger)

Now that the handler is running you can configure your logging. Below is a sample config using python's dictConfig.

from logging.config import dictConfig

log_config = {
    "version": 1,
    "formatters": {
        "data_dog": {
            "()": 'datadoglog.DatadogFormatter',
            "app_key": "<datadog_api_key>",
            "env": "production",
            "service": "project-web",
            "source": "project",
        },
    },
    "handlers": {
        "dd_handler": {
            "class": 'logging.handlers.QueueHandler',
            "formatter": 'data_dog',
            "level": 'INFO',
            "queue": queue,
        },
    },
    "loggers": {
        "root": {
            "level": "DEBUG",
            "handlers": ["dd_handler"],
        },
    },
}

# set the config
dictConfig(log_config)