Skip to main content

Pure python logging handler for writing logs to the journald using native protocol

Project description

logging-journald

PyPI - License Wheel PyPI PyPI Coverage Status tests

Pure python logging handler for writing logs to the journald using native protocol.

import logging
from logging_journald import JournaldLogHandler, check_journal_stream

# Use python default handler
LOG_HANDLERS = None


if (
    # Check if program running as systemd service
    check_journal_stream() or
    # Check if journald socket is available
    JournaldLogHandler.SOCKET_PATH.exists()
):
    LOG_HANDLERS = [JournaldLogHandler()]

logging.basicConfig(level=logging.INFO, handlers=LOG_HANDLERS)
logging.info("Hello logging world.")

MESSAGE_ID field

As defined in catalog documentation:

A 128-bit message identifier ID for recognizing certain message types, if this is desirable. This should contain a 128-bit ID formatted as a lower-case hexadecimal string, without any separating dashes or suchlike. This is recommended to be a UUID-compatible ID, but this is not enforced, and formatted differently. Developers can generate a new ID for this purpose with systemd-id128 new.

So you're free to choose how you want to act. By default, MESSAGE_ID is generated as a hash of the message and some static fields. But you can disable this by passing use_message_id=False to the class constructor.

from logging_journald import JournaldLogHandler

...

handler = JournaldLogHandler(use_message_id=False)

...

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

logging_journald-0.6.8.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

logging_journald-0.6.8-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file logging_journald-0.6.8.tar.gz.

File metadata

  • Download URL: logging_journald-0.6.8.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/23.5.0

File hashes

Hashes for logging_journald-0.6.8.tar.gz
Algorithm Hash digest
SHA256 3218e067f281315c43cd882a421317651766dd9602bd0a0c6b887c707f6f7d5d
MD5 978657c7d4d6d7c988d0011cd8f51283
BLAKE2b-256 47723440fb9b70e1f60b1ac826c30db7966b81d14a6eef554357640b9546482a

See more details on using hashes here.

File details

Details for the file logging_journald-0.6.8-py3-none-any.whl.

File metadata

File hashes

Hashes for logging_journald-0.6.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6b92c3810120629f2a0c6833b03cc6aa9c74d6f531aee71c6a7aaa50f455b175
MD5 43554e773d89b82b38a2db3de407ebc6
BLAKE2b-256 1c9d86f40db5094c31e300a4bd84e3ccd17e5b525f8df7278c94d84432cd908b

See more details on using hashes here.

Supported by

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