nextlog


Namenextlog JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/sourav-py/nextlog
SummaryA logging library with asynchronous logs dispatch to Loki.
upload_time2024-08-09 14:08:26
maintainerNone
docs_urlNone
authorSourav
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [nextlog](https://pypi.org/project/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.<br>
Whenever the logger statement - `logger.info()` / `logger.debug()` / `logger.error()` etc. gets executed, the log is pushed onto a `redis` queue.<br>
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
1. Download the zip file from Git Repo
2. Unzip
3. Go to root folder for `nextlog`
### Setup Virtual Enviroment and install nextlog locally
1. `python -m venv venv`
2. `source venv/bin/activate`  # On Windows use `venv\Scripts\activate`
3. `pip install -e .` This installs nextlog via the nextlog folder rather than though pip
4. Local Nextlog should be importable via `from nextlog import Logger`

---

## Examples

### Check out the [Examples](examples) folder for two examples.

The [basic example](examples/basic_example.py) 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](examples/application_example.py) 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


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sourav-py/nextlog",
    "name": "nextlog",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Sourav",
    "author_email": "imsrv2k@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/68/2e660b2e47cd2038c42e2989d20da8cd158a870122b67c6a08e2358bb761/nextlog-2.0.1.tar.gz",
    "platform": null,
    "description": "# [nextlog](https://pypi.org/project/nextlog/)\nThis is a `python` logging library which asynchronously dispatches logs to monitoring services like loki.\nIt uses the OOTB python logging library as its base.<br>\nWhenever the logger statement - `logger.info()` / `logger.debug()` / `logger.error()` etc. gets executed, the log is pushed onto a `redis` queue.<br>\nA process running on separate thread will keep dispatching those logs to the specified loki endpoint.\n\n## Features\n- **Seamless Integration**: nextlog builds upon the Python logging library, so its usage is similar and familiar.\n- **Async Dispatch**: Logs are asynchronously dispatched to monitoring services like Loki, ensuring minimal impact on the main code flow.\n- **Redis Backup**: Utilizes Redis to temporarily store logs in case the monitoring service (e.g., Loki) is unavailable.\n\n## Setup\n### Install the library \n`pip3 install nextlog`\n### Setup redis server\n`docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest`\n\n---\n\n## Setup test enviroment from local source\n### Download the library from Git Repo\n1. Download the zip file from Git Repo\n2. Unzip\n3. Go to root folder for `nextlog`\n### Setup Virtual Enviroment and install nextlog locally\n1. `python -m venv venv`\n2. `source venv/bin/activate`  # On Windows use `venv\\Scripts\\activate`\n3. `pip install -e .` This installs nextlog via the nextlog folder rather than though pip\n4. Local Nextlog should be importable via `from nextlog import Logger`\n\n---\n\n## Examples\n\n### Check out the [Examples](examples) folder for two examples.\n\nThe [basic example](examples/basic_example.py) 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\n\nThe [application example](examples/application_example.py) 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.\n\n## Basic Usage\n\n```\nfrom nextlog import Logger\nimport logging\n\nloki_url = \"http://localhost:3100/api/prom/push\"\nredis_host='localhost' # Default is localhost\nredis_port=6379  # Default port is 6379\n\nlabels = {\n    'source' : 'localhost-x2'\n}\n\nlogger = Logger(__name__,loki_url=loki_url,labels=labels)\n\nlogger.setLevel(logging.INFO)\nfile_handler = logging.FileHandler('console2.log')\nconsole_handler = logging.StreamHandler()\nlogger.addHandler(file_handler)\nlogger.addHandler(console_handler)\n\nlogger.error(\"Error log 1\")\nlogger.error(\"Error log 2\")\nlogger.critical(\"Critical log 1\")\nlogger.critical(\"Critical log 2\")\nlogger.error(\"Error log 3\")\nlogger.stop() #Stop the logger and finish sending logs\n\n\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A logging library with asynchronous logs dispatch to Loki.",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/sourav-py/nextlog"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7bc835bc024ce6af64388d5e36aeda480e878fc26ae93d10d818f7f56b8eec1a",
                "md5": "0be0f25b89aa7a31ff8e692e684245c0",
                "sha256": "89b3805feeef1dbc43690aad3f32dc63a6b5e6d761c2b65593e565b7b7faccb4"
            },
            "downloads": -1,
            "filename": "nextlog-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0be0f25b89aa7a31ff8e692e684245c0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5775,
            "upload_time": "2024-08-09T14:08:25",
            "upload_time_iso_8601": "2024-08-09T14:08:25.519021Z",
            "url": "https://files.pythonhosted.org/packages/7b/c8/35bc024ce6af64388d5e36aeda480e878fc26ae93d10d818f7f56b8eec1a/nextlog-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33682e660b2e47cd2038c42e2989d20da8cd158a870122b67c6a08e2358bb761",
                "md5": "a26a87b218fa82a9a7965f0592869efa",
                "sha256": "fb28ed755cc12a3d963ea3e56d163403721503071f22d2aa499c0f83d7033a0f"
            },
            "downloads": -1,
            "filename": "nextlog-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a26a87b218fa82a9a7965f0592869efa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6784,
            "upload_time": "2024-08-09T14:08:26",
            "upload_time_iso_8601": "2024-08-09T14:08:26.780621Z",
            "url": "https://files.pythonhosted.org/packages/33/68/2e660b2e47cd2038c42e2989d20da8cd158a870122b67c6a08e2358bb761/nextlog-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-09 14:08:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sourav-py",
    "github_project": "nextlog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nextlog"
}
        
Elapsed time: 0.35150s