Metadata-Version: 2.1
Name: logging-extension
Version: 0.2.0
Summary: Extensions for the original logging module
Author-email: Nikita Bulavinov <jktujgxtu@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Nikita Bulavinov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/jktujg/logging-extension
Project-URL: Bug Tracker, https://github.com/jktujg/logging-extension/issues
Keywords: logging,formatter,handler,filter,JSON,thread
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE

### JSONFormatter
Format logs as JSON lines
### ThreadedHandler
Container of handlers for logging in a separate thread

### Configuration example
#### in code


```python
import logging
from logging_extension import ThreadedHandler, JSONFormatter

logging.basicConfig(level=logging.DEBUG)
logging.getLogger().handlers.clear()

handler = logging.StreamHandler()
formatter = JSONFormatter(fmt_keys=dict(
    logger='name',
    level='levelno'
))

handler.setFormatter(formatter)
threaded_handler = ThreadedHandler(stream_handler=handler)

logging.getLogger().addHandler(threaded_handler)
logging.getLogger().debug('debug_msg', extra={'extra': 'value'})
```

    {"logger": "root", "level": 10, "created": "2024-05-12T11:43:19.171675+00:00", "message": "debug_msg", "extra": "value"}


#### via config


```python
import logging.config

# Usually defined in .json or .yml file
config = {
    "version": 1,
    "disable_existing_handlers": False,
    "formatters": {
        "json_formatter": {
            "()": "logging_extension.JSONFormatter",
            "fmt_keys": {
                "name": "name",
                "level": "levelno",
                "line": "lineno"
            }
        }
    },
    "handlers": {
        "stream_handler": {
            "class": "logging.StreamHandler",
            "stream": "ext://sys.stdout",
            "formatter": "json_formatter"
        },
        "threaded_handler": {
            "()": "logging_extension.ThreadedHandler",
            "stream_handler": "cfg://handlers.stream_handler"
        }
    },
    "loggers": {
        "root": {
            "level": "DEBUG",
            "handlers": [
                "threaded_handler"
            ]
        }
    }
}

logging.config.dictConfig(config)
logging.getLogger().debug('debug_msg', extra={'extra': 'value'})
```

    {"name": "root", "level": 10, "line": 39, "created": "2024-05-12T11:43:19.179082+00:00", "message": "debug_msg", "extra": "value"}


### BelowLevelFilter
Allows logs only below a specified level
#### Example


```python
from logging_extension import BelowLevelFilter

level_filter = BelowLevelFilter(level=logging.ERROR)
logging.getLogger().addFilter(level_filter)
logging.getLogger().addHandler(logging.StreamHandler())

logging.getLogger().error('error_msg')
logging.getLogger().warning('warning_msg')
```

    warning_msg

