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

You also need to install one of the journald binding implementations:

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.4.0.tar.gz (99.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.4.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: structlog_journald-0.4.0.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for structlog_journald-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8f51e18e3c48accfebcd2a083f863bbf51878efae4d743b07b9e93e93c863ec8
MD5 683f67456920b2ea13dd70fea1e1d17d
BLAKE2b-256 ffb1e481bc23d9160510c29478e155f03a05f791c0988e7547793d02a096358c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for structlog_journald-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 313ffa5925e8b780effd00b3b183736ac9ef0285047e56a7ba1972585e19d105
MD5 93795893eb734820f4a44c2b1d0ae620
BLAKE2b-256 bb7af7dc1fa1b0a3d7f03e82737e3c77c406f095f5051c2b85e4d8e128c5a52c

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 Pingdom Monitoring Sentry Error logging StatusPage Status page