Python logging logstash handler
Project description
sag_py_logging_logstash
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
- Install pycharm plugin BlackConnect
- Configure the python interpreter/venv
- pip install requirements-dev.txt
- pip install black[d]
- Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files
- Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat
- Ctl+Alt+S => Click Tools => BlackConnect => "Load from pyproject.yaml" (ensure line length is 120)
- Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the "local instance" config (e.g. C:\Python310\Scripts\blackd.exe)
- Ctl+Alt+S => Click Tools => Actions on save => Reformat code
- 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
Built Distribution
Hashes for sag_py_logging_logstash-3.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94cdb78e4616fbfea909c955de889babaaf3247e7b3785ee192caff0f2c5831d |
|
MD5 | 9a8224a760a7a83d6f63f6e8c1708b45 |
|
BLAKE2b-256 | 78f41e9eef3c15c024e0c7035f91165e2d083fb3d2c89228b0e73edb9901e6b1 |
Hashes for sag_py_logging_logstash-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c966484cdc8d26cd581ff77aed5493dfe9b717475a6ce472b118f9dbfa56f9a |
|
MD5 | bc4ac97845106b42f519f58209e08cf1 |
|
BLAKE2b-256 | 25541b6cb3d1e3df8a2a317f174827a215c14af0d1d7e1085e19de39330c0496 |