Skip to main content

Python logging logstash handler

Project description

sag_py_logging_logstash

Maintainability Coverage Status Known Vulnerabilities

Python Logstash Async is an asynchronous Python logging handler to submit log events to a remote Logstash instance. It based on open source library, see the documentation http://python-logstash-async.readthedocs.io/en/latest/. In this version transporter is limited to HTTPTransport, according to Logstash intern installation requirements.

Unlike most other Python Logstash logging handlers, this package works asynchronously by collecting log events from Python's logging subsystem and then transmitting the collected events in a separate worker thread to Logstash. This way, the main application (or thread) where the log event occurred, doesn't need to wait until the submission to the remote Logstash instance succeeded.

This is especially useful for applications like websites or web services or any kind of request serving API where response times matter.

Usage

Example::

from logstash_async.handler import AsynchronousLogstashHandler
from logstash_async.formatter import LogstashFormatter
import logging

logstash_handler = AsynchronousLogstashHandler(
    host='my_host',
    port=123,
    username='my_user',
    password='my_password',
    index_name = 'my_index')
logstash_formatter = LogstashFormatter( extra_prefix='',
extra={'customer': "name", 'ap_environment': "local"})
logstash_handler.setFormatter(logstash_formatter)

logging_handlers = []
logging_handlers.append(logstash_handler)

logging.basicConfig(
level="INFO",
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=logging_handlers)

logging.getLogger().info("Logging Message", extra = {'new_field':"value"})

Installation

pip install sag-py-logging-logstash

How to start developing

With vscode

Just install vscode with dev containers extension. All required extensions and configurations are prepared automatically.

With pycharm

  • Install latest pycharm
  • Configure the python interpreter/venv
  • pip install requirements-dev.txt
  • Restart pycharm

How to publish

  • Update the version in setup.py and commit your change
  • Create a tag with the same version number
  • Let github do the rest

How to test

To avoid publishing to pypi unnecessarily you can do as follows

  • Tag your branch however you like
  • Use the chosen tag in the requirements.txt-file of the project you want to test this library in, eg. sag_py_logging_logstash==<your tag>
  • Rebuild/redeploy your project

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

sag_py_logging_logstash-3.0.4.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sag_py_logging_logstash-3.0.4-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file sag_py_logging_logstash-3.0.4.tar.gz.

File metadata

  • Download URL: sag_py_logging_logstash-3.0.4.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sag_py_logging_logstash-3.0.4.tar.gz
Algorithm Hash digest
SHA256 2ce8e541f159360c8e8227b94bd4a36590bb1806d8a1a178ed45632473b2e6a5
MD5 d04fe617abc1288c4a40ac56a41dbb58
BLAKE2b-256 1a4aa14c36b66307ddf267a05a544693780cd1db9b18bcb8472b98df1bfbeb49

See more details on using hashes here.

File details

Details for the file sag_py_logging_logstash-3.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sag_py_logging_logstash-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4c4edd78fe33fb69079800b7b2da7d61db27acbb91a425f2b8564573097279de
MD5 63722052bf537c909729881c6066b442
BLAKE2b-256 da0b255ae75204eb01c93d80847982413ad13073fd5dcec98b029c4ff00f71fc

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