Daiquiri (Logging Library)

3.4.0 · active · verified Thu Apr 16

Daiquiri is a Python library designed to simplify the configuration of Python's built-in `logging` module. It provides an easy-to-use interface for setting up basic logging functionalities, including custom formatters and handlers, often with a single call to `daiquiri.setup()`. The library is actively maintained, with its current version being 3.4.0, and has a consistent update cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize Daiquiri for basic logging to `stderr` with colored output. It also shows how to obtain a logger instance and log messages at different levels, including custom keyword arguments which Daiquiri supports natively. An commented-out example for JSON file logging is also provided, highlighting the need for an additional dependency.

import logging
import daiquiri

# Basic setup to log to stderr with colors
daiquiri.setup(level=logging.INFO)

# Get a logger instance
logger = daiquiri.getLogger(__name__)

logger.info('This is an info message.')
logger.warning('This is a warning message.')
logger.error('This is an error message with extra context!', user_id='123', transaction_id='abc')

# Example with JSON output to a file (requires 'pip install python-json-logger')
# from daiquiri.output import File
# from daiquiri.formatter import JSON_FORMATTER
# daiquiri.setup(
#     level=logging.INFO,
#     outputs=(
#         File('app.log', formatter=JSON_FORMATTER),
#     )
# )
# logger_json = daiquiri.getLogger('json_example')
# logger_json.info('JSON message', data={'key': 'value'})

view raw JSON →