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.5.0.tar.gz (100.7 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.5.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for structlog_journald-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8adc28fcbe5992eea0816126c48f52b30630e63fe2b94e00dfb1da55b9b25d20
MD5 2a29a878e14c7c6a1e3ebaa67666bf4d
BLAKE2b-256 decf307d3f277a2f2d59ed2461c385f200c5f7d6e472843868fa43d9845e8509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for structlog_journald-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2d0f69bb21ecafb83b40442d049f82ece9eb54ab7eb294c82d4ee14fc7431a5
MD5 082b5390a8b5af0a0c353630a8d65ee7
BLAKE2b-256 b64d4434a79ece1d77f1514abe1b3d3326ba2f8d72904e7f738498ccd58a527f

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