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.

Metadata

Release files for datadog-logger 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datadog-logger 1.0.3
File Size Uploaded
datadog_logger-1.0.3.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for datadog-logger 1.0.3
File Interpreter ABI Platform
datadog_logger-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / datadog_logger-1.0.3.tar.gz

Download URL datadog_logger-1.0.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1284ad80d7d338ab3722dc027859abf0772074e1891170e43b2ed6cefc587179
BLAKE2b-256 checksum
How to use checksums
1ee1216e553472c79ddf042e17f6a75e448502806e2b878860ca974664dcddd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/7.0.0-1008-aws

Release files / datadog_logger-1.0.3-py3-none-any.whl

Download URL datadog_logger-1.0.3-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee06e448a7811351652a27faff205554df6537d702d9172d3c81d5c9735334c2
BLAKE2b-256 checksum
How to use checksums
2587acc014567b73b14b48f25c29c1dd134f1939a5bd8f890887183c8cf3ab85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Linux/7.0.0-1008-aws

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.0

1 release file

0.2.0

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page