nextlog
This is a python logging library which asynchronously dispatches logs to monitoring services like loki.
It uses the OOTB python logging library as its base.
Whenever the logger statement - logger.info() / logger.debug() / logger.error() etc. gets executed, the log is pushed onto a redis queue.
A process running on separate thread will keep dispatching those logs to the specified loki endpoint.
Features
- Seamless Integration: nextlog builds upon the Python logging library, so its usage is similar and familiar.
- Async Dispatch: Logs are asynchronously dispatched to monitoring services like Loki, ensuring minimal impact on the main code flow.
- Redis Backup: Utilizes Redis to temporarily store logs in case the monitoring service (e.g., Loki) is unavailable.
Setup
Install the library
pip3 install nextlog
Setup redis server
docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
Setup test enviroment from local source
Download the library from Git Repo
- Download the zip file from Git Repo
- Unzip
- Go to root folder for
nextlog
Setup Virtual Enviroment and install nextlog locally
python -m venv venvsource venv/bin/activate# On Windows usevenv\Scripts\activatepip install -e .This installs nextlog via the nextlog folder rather than though pip- Local Nextlog should be importable via
from nextlog import Logger
Examples
Check out the Examples folder for two examples.
The basic example is a simple way to use Nextlog to send logs, but does not use optional features like exit methods and shared flags that would exist in an application
The application example is a quick start example to use Nextlog in a more robust application. This allows Nextlog to exit the main application if there are errors in logging setup (like connecting to redis or grafana) and more robust commenting for options.
Basic Usage
from nextlog import Logger
import logging
loki_url = "http://localhost:3100/api/prom/push"
redis_host='localhost' # Default is localhost
redis_port=6379 # Default port is 6379
labels = {
'source' : 'localhost-x2'
}
logger = Logger(__name__,loki_url=loki_url,labels=labels)
logger.setLevel(logging.INFO)
file_handler = logging.FileHandler('console2.log')
console_handler = logging.StreamHandler()
logger.addHandler(file_handler)
logger.addHandler(console_handler)
logger.error("Error log 1")
logger.error("Error log 2")
logger.critical("Critical log 1")
logger.critical("Critical log 2")
logger.error("Error log 3")
logger.stop() #Stop the logger and finish sending logs
Metadata
Release files for nextlog 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nextlog-2.0.1.tar.gz | 6.8 kB | Without provenance | Details for nextlog-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nextlog-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for nextlog-2.0.1-py3-none-any.whl |
Total release size: 12.6 kB
Release files / nextlog-2.0.1.tar.gz
| Download URL | nextlog-2.0.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb28ed755cc12a3d963ea3e56d163403721503071f22d2aa499c0f83d7033a0f
|
|
BLAKE2b-256 checksum How to use checksums |
33682e660b2e47cd2038c42e2989d20da8cd158a870122b67c6a08e2358bb761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / nextlog-2.0.1-py3-none-any.whl
| Download URL | nextlog-2.0.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
89b3805feeef1dbc43690aad3f32dc63a6b5e6d761c2b65593e565b7b7faccb4
|
|
BLAKE2b-256 checksum How to use checksums |
7bc835bc024ce6af64388d5e36aeda480e878fc26ae93d10d818f7f56b8eec1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for nextlog 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.