structlog-journald


Namestructlog-journald JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryStructlog processor to send logs to journald
upload_time2025-07-13 12:44:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords journald logging structlog systemd
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # structlog-journald

![made-in-vietnam](https://madewithlove.vercel.app/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d)
[![structlog-journald](https://badge.fury.io/py/structlog-journald.svg)](https://pypi.org/project/structlog-journald/)
[![ReadTheDocs](https://readthedocs.org/projects/structlog-journald/badge/?version=latest)](https://structlog-journald.readthedocs.io?badge=latest)
[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)

[Structlog] processor to send logs to [journald].

Documentation: [https://structlog-journald.readthedocs.io](https://structlog-journald.readthedocs.io)

Installation
------------

To install `structlog-journald`, run:

```sh
pip install structlog-journald
```

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

- CPython-based [`systemd-python`](https://pypi.org/project/systemd-python/).
- Cython-based [`cysystemd`](https://pypi.org/project/cysystemd/).

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:

```py
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](https://raw.githubusercontent.com/hongquan/structlog-journald/refs/heads/main/misc/screenshot.png)

[structlog]: https://www.structlog.org
[journald]: https://www.freedesktop.org/software/systemd/man/latest/journalctl.html

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "structlog-journald",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "journald, logging, structlog, systemd",
    "author": null,
    "author_email": "Nguy\u1ec5n H\u1ed3ng Qu\u00e2n <ng.hong.quan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ff/b1/e481bc23d9160510c29478e155f03a05f791c0988e7547793d02a096358c/structlog_journald-0.4.0.tar.gz",
    "platform": null,
    "description": "# structlog-journald\n\n![made-in-vietnam](https://madewithlove.vercel.app/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d)\n[![structlog-journald](https://badge.fury.io/py/structlog-journald.svg)](https://pypi.org/project/structlog-journald/)\n[![ReadTheDocs](https://readthedocs.org/projects/structlog-journald/badge/?version=latest)](https://structlog-journald.readthedocs.io?badge=latest)\n[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)\n\n[Structlog] processor to send logs to [journald].\n\nDocumentation: [https://structlog-journald.readthedocs.io](https://structlog-journald.readthedocs.io)\n\nInstallation\n------------\n\nTo install `structlog-journald`, run:\n\n```sh\npip install structlog-journald\n```\n\nYou also need to install one of the journald binding implementations:\n\n- CPython-based [`systemd-python`](https://pypi.org/project/systemd-python/).\n- Cython-based [`cysystemd`](https://pypi.org/project/cysystemd/).\n\nUsage\n-----\n\nAdd the `structlog_journald.JournaldProcessor` to your list of `structlog` processors.\nIt will do nothing if the journald socket is not available,\nin other words, the app was not started by systemd.\n\nTo let the log have more useful information, you should also add these processors before `JournaldProcessor`:\n\n- `CallsiteParameterAdder`\n- `format_exc_info`\n\nExample:\n\n```py\nimport getpass\nimport logging\nimport platform\n\nimport structlog\n\nfrom structlog_journald import JournaldProcessor\n\n\nstructlog.configure(\n    processors=[\n        structlog.contextvars.merge_contextvars,\n        structlog.processors.add_log_level,\n        structlog.processors.CallsiteParameterAdder(),\n        structlog.processors.format_exc_info,\n        structlog.dev.set_exc_info,\n        structlog.processors.TimeStamper(fmt='%Y-%m-%d %H:%M:%S', utc=False),\n        structlog.processors.EventRenamer('message'),\n        JournaldProcessor(),\n        # This processor should be added for development environment only.\n        structlog.dev.ConsoleRenderer(),\n    ],\n    # In this example, we want to print log entries of all levels\n    wrapper_class=structlog.make_filtering_bound_logger(logging.NOTSET),\n    context_class=dict,\n    logger_factory=structlog.WriteLoggerFactory(),\n    cache_logger_on_first_use=True,\n)\n\nlog = structlog.stdlib.get_logger()\n\nuser = getpass.getuser()\n\n\nlog.info('Current Linux user: %s', user, linux=platform.freedesktop_os_release())\nlog.warning('This is a warning.', platform=platform.platform())\ntry:\n    int('abc')\nexcept ValueError:\n    log.exception('Failed to convert string to integer.')\n```\n\n![Journalctl](https://raw.githubusercontent.com/hongquan/structlog-journald/refs/heads/main/misc/screenshot.png)\n\n[structlog]: https://www.structlog.org\n[journald]: https://www.freedesktop.org/software/systemd/man/latest/journalctl.html\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Structlog processor to send logs to journald",
    "version": "0.4.0",
    "project_urls": {
        "Changelog": "https://github.com/hongquan/structlog-journald/blob/main/CHANGELOG.md",
        "Documentation": "https://structlog-journald.readthedocs.io",
        "Homepage": "https://github.com/hongquan/structlog-journald",
        "Repository": "https://github.com/hongquan/structlog-journald"
    },
    "split_keywords": [
        "journald",
        " logging",
        " structlog",
        " systemd"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bb7af7dc1fa1b0a3d7f03e82737e3c77c406f095f5051c2b85e4d8e128c5a52c",
                "md5": "93795893eb734820f4a44c2b1d0ae620",
                "sha256": "313ffa5925e8b780effd00b3b183736ac9ef0285047e56a7ba1972585e19d105"
            },
            "downloads": -1,
            "filename": "structlog_journald-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "93795893eb734820f4a44c2b1d0ae620",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 6407,
            "upload_time": "2025-07-13T12:44:47",
            "upload_time_iso_8601": "2025-07-13T12:44:47.755291Z",
            "url": "https://files.pythonhosted.org/packages/bb/7a/f7dc1fa1b0a3d7f03e82737e3c77c406f095f5051c2b85e4d8e128c5a52c/structlog_journald-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ffb1e481bc23d9160510c29478e155f03a05f791c0988e7547793d02a096358c",
                "md5": "683f67456920b2ea13dd70fea1e1d17d",
                "sha256": "8f51e18e3c48accfebcd2a083f863bbf51878efae4d743b07b9e93e93c863ec8"
            },
            "downloads": -1,
            "filename": "structlog_journald-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "683f67456920b2ea13dd70fea1e1d17d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 99330,
            "upload_time": "2025-07-13T12:44:49",
            "upload_time_iso_8601": "2025-07-13T12:44:49.782857Z",
            "url": "https://files.pythonhosted.org/packages/ff/b1/e481bc23d9160510c29478e155f03a05f791c0988e7547793d02a096358c/structlog_journald-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-13 12:44:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hongquan",
    "github_project": "structlog-journald",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "structlog-journald"
}
        
Elapsed time: 0.94756s