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

Python logging handlers for sending logs to Data Dog

License

Notifications You must be signed in to change notification settings

gadventures/datadoglog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Python logging handlers for sending logs to Data Dog

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages