Skip to main content

Structlog processor to send logs to journald

Project description

structlog-journald

made-in-vietnam structlog-journald ReadTheDocs Common Changelog

Structlog processor to send logs to journald.

Documentation: https://structlog-journald.readthedocs.io

Installation

To install structlog-journald, run:

pip install structlog-journald

Or with uv:

uv add structlog-journald

Usage

Add the structlog_journald.JournaldProcessor to your list of structlog processors. It will do nothing if the journald socket is not available, in other words, the app was not started by systemd.

To let the log have more useful information, you should also add these processors before JournaldProcessor:

  • CallsiteParameterAdder
  • format_exc_info

Example:

import getpass
import logging
import platform

import structlog

from structlog_journald import JournaldProcessor


structlog.configure(
    processors=[
        structlog.contextvars.merge_contextvars,
        structlog.processors.add_log_level,
        structlog.processors.CallsiteParameterAdder(),
        structlog.processors.format_exc_info,
        structlog.dev.set_exc_info,
        structlog.processors.TimeStamper(fmt='%Y-%m-%d %H:%M:%S', utc=False),
        structlog.processors.EventRenamer('message'),
        JournaldProcessor(),
        # This processor should be added for development environment only.
        structlog.dev.ConsoleRenderer(),
    ],
    # In this example, we want to print log entries of all levels
    wrapper_class=structlog.make_filtering_bound_logger(logging.NOTSET),
    context_class=dict,
    logger_factory=structlog.WriteLoggerFactory(),
    cache_logger_on_first_use=True,
)

log = structlog.stdlib.get_logger()

user = getpass.getuser()


log.info('Current Linux user: %s', user, linux=platform.freedesktop_os_release())
log.warning('This is a warning.', platform=platform.platform())
try:
    int('abc')
except ValueError:
    log.exception('Failed to convert string to integer.')

Journalctl

Project details


Download files

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

Source Distribution

structlog_journald-1.0.0.tar.gz (125.3 kB view details)

Uploaded Source

Built Distribution

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

structlog_journald-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file structlog_journald-1.0.0.tar.gz.

File metadata

  • Download URL: structlog_journald-1.0.0.tar.gz
  • Upload date:
  • Size: 125.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for structlog_journald-1.0.0.tar.gz
Algorithm Hash digest
SHA256 230bbf8489217bb98058ea146e311eafa49417b8dc46876ecf155d0d51d4cf59
MD5 81294346dabc302054b3494803c9022a
BLAKE2b-256 e98d336f540f7592307cdf8a3b445dd3bc87a17891e3ad68717d22b834a4494f

See more details on using hashes here.

Provenance

The following attestation bundles were made for structlog_journald-1.0.0.tar.gz:

Publisher: ci.yml on hongquan/structlog-journald

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file structlog_journald-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for structlog_journald-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa09a7485070ccd58e56754de327d5c1062a06cd222d5128cfe49d0cf5ebc4c
MD5 bb5220b6ebaf7f7fc746a3050335cde6
BLAKE2b-256 92021835b6d29da8eb5a1d4f8ed1c57259091711084cb1d5d3422e320e9960c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for structlog_journald-1.0.0-py3-none-any.whl:

Publisher: ci.yml on hongquan/structlog-journald

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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