Metadata-Version: 2.1
Name: Non-Blocking-Http-Logging-Handler
Version: 1.0.4
Summary: Python logging handler that sends log records to a HTTP server in a non-blocking way.
Home-page: https://github.com/whoami-jc/non-blocking-http-logging-handler
Author: Juan Carlos
Author-email: whoami0jc@gmail.com
License: License :: OSI Approved :: MIT License
Description: # Non-Blocking-Http-Logging-Handler
        
        
        [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
        ![Python Versions](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)
        
        This library provides a non-blocking http logging handler for python 3.8+ that can be used to send logs to a logging 
        service in a non-blocking way via http requests in a very simple way.
        
        ## Installation
        
        ```bash
        pip install non-blocking-http-logging-handler
        ```
        
        ## Basic Usage
        
        ```python
        import logging
        
        from non_blocking_http_handler.handler import NonBlockingHttpHandler
        
        httpHandler = NonBlockingHttpHandler(
            url='http://localhost:5000/logs',
            max_workers=10,
            max_retries=3
        )
        
        log = logging.getLogger()
        log.setLevel(logging.DEBUG)  # set level to DEBUG to see all logs
        log.addHandler(httpHandler)
        ```
        
        The complete example is available in the examples folder in the file `basic_usage.py`.
        
        ### Parameters explanation
        
        - `url`: The url of the logging service.
        - `max_workers`: The maximum number of workers that will be used to send logs to the logging service.
        - `max_retries`: The maximum number of retries that will be done if the request fails.
        - `extra`: A dictionary with extra fields that will be added to the log (explained below).
        
        ### Output format
        
        The output format of the logs is a json with the following fields:
        - `level`: The level of the log.
        - `message`: The message of the log.
        - `file`: The file name of the log.
        - `line`: The line number of the log.
        - `timestamp`: The timestamp of the log.
        - the extra fields that you may have added to the log.
        
        for example:
        
        ```json
        {
            "level": "INFO",
            "message": "This is a log",
            "file": "basic_usage.py",
            "line": 10,
            "timestamp": "2021-10-10 10:10:10"
        }
        ```
        
        ## Add extra fields to the log
        
        In same cases you may want to add extra fields to the log, for example, 
        if you are using a logging handler to send logs to a logging service, 
        you may want to add the service name to the log or the ip.
        
        For this purpose, you can use the `extra` parameter of the `NonBlockingHttpHandler` class.
        
        ```python
        import logging
        import socket  # for get hostname amd ip
        
        from non_blocking_http_handler.handler import NonBlockingHttpHandler
        
        httpHandler = NonBlockingHttpHandler(
            url='http://localhost:5000/logs',
            max_workers=5,
            max_retries=3,
            extra={
                'hostname': socket.gethostname()
            }
        )
        
        log = logging.getLogger()
        log.setLevel(logging.DEBUG)  # set level to DEBUG to see all logs
        log.addHandler(httpHandler)
        ```
        
        The complete example is available in the examples folder in the file `extra_fields.py`.
        
        
        
        
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Environment :: Console
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS
Classifier: Operating System :: OS Independent
Classifier: Operating System :: Microsoft :: Windows
Description-Content-Type: text/markdown
