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-0.6.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-0.6.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: structlog_journald-0.6.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-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0eafb431a97f01637e122756b52041b33847059fa5a85eac65fd526ad8ad7b91
MD5 1e2b43fc256233a02977b743b2419ac8
BLAKE2b-256 6cca5773257863ca47bf871bf4c589deb418d2070bb2df0b4c94569d0a41c820

See more details on using hashes here.

Provenance

The following attestation bundles were made for structlog_journald-0.6.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-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for structlog_journald-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15baa12cf5ab523a45b60536d07071d846d1002e2e891564cfa7dbc2e05db24c
MD5 936dc6722d4f6fc1f8679594b9f7eab4
BLAKE2b-256 236be4d468ef2d12c87d622b669d4a911c4599df4058318061b3899ef249cc7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for structlog_journald-0.6.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