Skip to main content

DataDog Logger

Note: This library does not send logs to Datadog's Log Management product. See Datadog's documentation for how to configure log collection. See https://docs.datadoghq.com/logs/log_collection/

A Python logging.Handler for sending log messages to DataDog as Events in the Events Explorer.

Installation

pip install datadog-logger

Usage

The simplest way to enable logging to DataDog is to use the log_error_events helper, which will cause all logging.ERROR and higher messages to be sent to DataDog:

import datadog
from datadog_logger import log_error_events
import logging

# Authenticate with DataDog
datadog.initialize(api_key="api-key", app_key="app-key")

# Note, a normal STDOUT handler will not be configured if this is not
# called first
logging.basicConfig()

log_error_events(tags=["tag1:value", "tag2:value"], mentions=["@devs", "@slack"])

logging.error("Oh no!")

This will enable the handler on the root logger; tags and mentions may both be None, in which case none will be included. The handler will have a log level of logging.ERROR, meaning only ERROR and CRITICAL (or any higher custom levels) will be sent to DataDog.

A specific logger may also be specified by name:

log_error_events("some.logger")

Details

The Handler may also be created and added to a logger manually:

import datadog
from datadog_logger import DatadogLogHandler
import logging

datadog.initialize(api_key="api-key", app_key="app-key")

datadog_handler = DatadogLogHandler(
    tags=["some:tag"], mentions=["@some-mention"], level=logging.WARNING)

# Enable STDOUT logging
logging.basicConfig()

# The root logger
logger = logging.getLogger()
logger.addHandler(datadog_handler)

# This will be logged, because the level is WARNING
logger.warning("Watch out!")

# This will not
logger.info("Lets not log everything to DataDog")

When the event is created, the msg of the log record will be passed as the title of the event. Normally, this would be the string passed into the logging call, with any % substitutions applied.

The text of the event will be the formatted record. If the log record includes exc_info (i.e. because you called logging.exception, or passed exc_info to the log function), then the full stack trace will be included in the event text.

Any @mentions passed via the mentions constructor argument will be appended to the end of the text, so this library can be used to alert, via DataDog, on particular log messages.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datadog_logger-1.0.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datadog_logger-1.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file datadog_logger-1.0.3.tar.gz.

File metadata

  • Download URL: datadog_logger-1.0.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/7.0.0-1008-aws

File hashes

Hashes for datadog_logger-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1284ad80d7d338ab3722dc027859abf0772074e1891170e43b2ed6cefc587179
MD5 403b64cf1b3376311d799400e2f4f55f
BLAKE2b-256 1ee1216e553472c79ddf042e17f6a75e448502806e2b878860ca974664dcddd9

See more details on using hashes here.

File details

Details for the file datadog_logger-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: datadog_logger-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/7.0.0-1008-aws

File hashes

Hashes for datadog_logger-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ee06e448a7811351652a27faff205554df6537d702d9172d3c81d5c9735334c2
MD5 9c15695bdb478b3c738737f7344e9971
BLAKE2b-256 2587acc014567b73b14b48f25c29c1dd134f1939a5bd8f890887183c8cf3ab85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page