Skip to main content

Simplifies logging for systemd

Project description

release lic coverage


Simplifies logging for systemd

Requires Python 3.6+

  • No need to compile (pure Python), uses

  • Simplified configuration.

  • Just logging. Nothing more.


import logging

from systemdlogging.toolbox import init_systemd_logging

# This one line in most cases would be enough.
# By default it attaches systemd logging handler to a root Python logger.
init_systemd_logging()  # Returns True if initialization went fine.

# Now you can use logging as usual.
logger = logging.getLogger(__name__)

logger.debug('My debug message')

    raise ValueError('Log me please')

except ValueError:
    # Additional context can be passed in extra.context.
    logger.exception('Something terrible just happened', extra={
        'message_id': True,  # Generate message ID automatically.
        'context': {
            'FIELD1': 'one',
            'FIELD2': 'two',
    }, stack_info=True)

Read the docs to find out more.


Debug runs

  1. Run your script with:

$ sudo systemd-run -u debugme -t /usr/bin/python /home/my/
  1. Watch its journal with:

$ journalctl -u debugme -f -o verbose

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

systemd-logging-1.0.1.tar.gz (12.4 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page