Name | logging-extension JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | Extensions for the original logging module |
upload_time | 2024-07-29 13:06:36 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
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. |
keywords |
logging
formatter
handler
filter
json
thread
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# logging-extenson
Extension of built-in python module `logging`
## Instalation
```
pip install logging-extension
```
## Extensions
### JSONFormatter
Formats logs in JSON format
<details>
<summary>
Configuration example
</summary>
```python
import logging
from logging_extension import JSONFormatter
json_formatter = JSONFormatter(fmt_keys=dict(
logger='name',
level='levelno',
))
logging.basicConfig(level='DEBUG', force=True)
logging.getLogger().handlers[0].setFormatter(json_formatter)
logging.getLogger().info('info_message', extra={'extra': ['value']})
```
{"logger": "root", "level": 20, "created": "2024-07-29T12:35:21.505616+00:00", "message": "info_message", "extra": ["value"]}
</details>
<details>
<summary>
Dictionary-based configuration example
</summary>
```python
import logging.config
config = {
"version": 1,
"disable_existing_handlers": False,
"formatters": {
"json_formatter": {
"()": "logging_extension.JSONFormatter",
"fmt_keys": {
"name": "name",
"level": "levelno",
}
}
},
"handlers": {
"stream_handler": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
"formatter": "json_formatter"
},
},
"root": {
"level": "DEBUG",
"handlers": [
"stream_handler"
]
}
}
logging.config.dictConfig(config)
logging.debug('debug_msg', extra={'extra': ['value']})
```
{"name": "root", "level": 10, "created": "2024-07-29T12:35:21.513188+00:00", "message": "debug_msg", "extra": ["value"]}
</details>
### LevelFilter
Logging level filter. Allows specifying a comparison function from the built-in `operator` module or providing your own.
<details>
<summary>
Configuration example
</summary>
```python
import logging
from logging_extension import LevelFilter
# `compare` argument also can be any function that compares levels
# e.g. compare(record_level: int, filter_level: int) -> bool: ...
only_error_filter = LevelFilter(level='ERROR', compare='eq', name='only_error_filter')
logging.basicConfig(level='DEBUG', force=True)
logging.getLogger().addFilter(only_error_filter)
logging.critical('skip critical')
logging.error('show error')
```
ERROR:root:show error
</details>
<details>
<summary>
Dictionary-based configuration example
</summary>
```python
import logging.config
config = {
"version": 1,
"disable_existing_handlers": False,
"filters": {
"only_error_filter": {
"()": "logging_extension.LevelFilter",
"level": "ERROR",
"compare": "eq",
}
},
"loggers": {
"root": {
"level": "DEBUG",
"filters": [
"only_error_filter",
]
}
}
}
logging.config.dictConfig(config)
logging.critical('skip critical', extra={'extra': 'value'})
logging.error('show error', extra={'extra': 'value'})
logging.getLogger().filters.clear()
```
ERROR:root:show error
</details>
### ThreadedHandler
Container for handlers that perform non-blocking logging in a separate thread.
Essentially, a wrapper around `QueueHandler` with automatic start of `QueueListener` using the provided handlers.
<details>
<summary>
Configuration example
</summary>
```python
import logging
from logging_extension import ThreadedHandler
threaded_handler = ThreadedHandler(
handler_0=logging.StreamHandler(),
handler_2=logging.StreamHandler(),
)
logging.basicConfig(force=True, level='DEBUG')
logging.getLogger().handlers = [threaded_handler]
logging.getLogger().warning('debug msg')
print('in main thread')
```
in main thread
debug msg
debug msg
</details>
<details>
<summary>
Dictionary-based configuration example
</summary>
```python
import logging.config
config = {
"version": 1,
"disable_existing_handlers": False,
"handlers": {
"stream_handler_0": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
"stream_handler_1": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
"threaded_handler": {
"()": "logging_extension.ThreadedHandler",
"handler_0": "cfg://handlers.stream_handler_0",
"handler_1": "cfg://handlers.stream_handler_1",
},
},
"root": {
"level": "DEBUG",
"handlers": [
"threaded_handler"
]
}
}
logging.config.dictConfig(config)
logging.getLogger().warning('debug msg')
print('in main thread')
```
debug msg
in main thread
debug msg
</details>
Raw data
{
"_id": null,
"home_page": null,
"name": "logging-extension",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "logging, formatter, handler, filter, JSON, thread",
"author": null,
"author_email": "Nikita Bulavinov <jktujgxtu@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/7b/51/49a3f8d1c2c2bf5993c47ca4d0e4e4f2665c02d7a3780b8c293b09ac7968/logging_extension-0.4.0.tar.gz",
"platform": null,
"description": "# logging-extenson\nExtension of built-in python module `logging`\n\n\n## Instalation\n```\npip install logging-extension\n```\n\n\n## Extensions\n### JSONFormatter\nFormats logs in JSON format\n<details>\n<summary>\nConfiguration example\n</summary>\n\n\n\n```python\nimport logging\nfrom logging_extension import JSONFormatter\n\n\njson_formatter = JSONFormatter(fmt_keys=dict(\n logger='name',\n level='levelno',\n))\n\nlogging.basicConfig(level='DEBUG', force=True)\nlogging.getLogger().handlers[0].setFormatter(json_formatter)\n\nlogging.getLogger().info('info_message', extra={'extra': ['value']})\n```\n\n {\"logger\": \"root\", \"level\": 20, \"created\": \"2024-07-29T12:35:21.505616+00:00\", \"message\": \"info_message\", \"extra\": [\"value\"]}\n\n\n\n</details>\n\n<details>\n<summary>\nDictionary-based configuration example\n</summary>\n\n\n\n```python\nimport logging.config\n\n\nconfig = {\n \"version\": 1,\n \"disable_existing_handlers\": False,\n \"formatters\": {\n \"json_formatter\": {\n \"()\": \"logging_extension.JSONFormatter\",\n \"fmt_keys\": {\n \"name\": \"name\",\n \"level\": \"levelno\",\n }\n }\n },\n \"handlers\": {\n \"stream_handler\": {\n \"class\": \"logging.StreamHandler\",\n \"stream\": \"ext://sys.stderr\",\n \"formatter\": \"json_formatter\"\n },\n },\n \"root\": {\n \"level\": \"DEBUG\",\n \"handlers\": [\n \"stream_handler\"\n ]\n }\n}\n\nlogging.config.dictConfig(config)\nlogging.debug('debug_msg', extra={'extra': ['value']})\n```\n\n {\"name\": \"root\", \"level\": 10, \"created\": \"2024-07-29T12:35:21.513188+00:00\", \"message\": \"debug_msg\", \"extra\": [\"value\"]}\n\n\n</details>\n\n### LevelFilter\nLogging level filter. Allows specifying a comparison function from the built-in `operator` module or providing your own.\n<details>\n<summary>\nConfiguration example\n</summary>\n\n\n```python\nimport logging \nfrom logging_extension import LevelFilter\n\n# `compare` argument also can be any function that compares levels\n# e.g. compare(record_level: int, filter_level: int) -> bool: ...\nonly_error_filter = LevelFilter(level='ERROR', compare='eq', name='only_error_filter')\n\nlogging.basicConfig(level='DEBUG', force=True)\nlogging.getLogger().addFilter(only_error_filter)\n\nlogging.critical('skip critical')\nlogging.error('show error')\n```\n\n ERROR:root:show error\n\n\n\n</details>\n\n\n<details>\n<summary>\nDictionary-based configuration example\n</summary>\n\n\n```python\nimport logging.config\n\nconfig = {\n \"version\": 1,\n \"disable_existing_handlers\": False,\n \"filters\": {\n \"only_error_filter\": {\n \"()\": \"logging_extension.LevelFilter\",\n \"level\": \"ERROR\",\n \"compare\": \"eq\",\n }\n \n },\n \"loggers\": {\n \"root\": {\n \"level\": \"DEBUG\",\n \"filters\": [\n \"only_error_filter\",\n ]\n }\n }\n}\nlogging.config.dictConfig(config)\n\nlogging.critical('skip critical', extra={'extra': 'value'})\nlogging.error('show error', extra={'extra': 'value'})\n\nlogging.getLogger().filters.clear()\n```\n\n ERROR:root:show error\n\n\n\n\n</details>\n\n### ThreadedHandler\nContainer for handlers that perform non-blocking logging in a separate thread.\nEssentially, a wrapper around `QueueHandler` with automatic start of `QueueListener` using the provided handlers.\n<details>\n<summary>\nConfiguration example\n</summary>\n\n\n\n\n\n\n\n\n\n\n```python\nimport logging\nfrom logging_extension import ThreadedHandler\n\n\nthreaded_handler = ThreadedHandler(\n handler_0=logging.StreamHandler(),\n handler_2=logging.StreamHandler(),\n)\n\nlogging.basicConfig(force=True, level='DEBUG')\nlogging.getLogger().handlers = [threaded_handler]\n\nlogging.getLogger().warning('debug msg')\nprint('in main thread')\n```\n in main thread\n debug msg\n debug msg\n\n</details>\n\n\n\n<details>\n<summary>\nDictionary-based configuration example\n</summary>\n\n\n\n```python\nimport logging.config\n\n\nconfig = {\n \"version\": 1,\n \"disable_existing_handlers\": False,\n \"handlers\": {\n \"stream_handler_0\": {\n \"class\": \"logging.StreamHandler\",\n \"stream\": \"ext://sys.stderr\",\n },\n \"stream_handler_1\": {\n \"class\": \"logging.StreamHandler\",\n \"stream\": \"ext://sys.stderr\",\n },\n \"threaded_handler\": {\n \"()\": \"logging_extension.ThreadedHandler\",\n \"handler_0\": \"cfg://handlers.stream_handler_0\",\n \"handler_1\": \"cfg://handlers.stream_handler_1\",\n },\n },\n \"root\": {\n \"level\": \"DEBUG\",\n \"handlers\": [\n \"threaded_handler\"\n ]\n }\n}\n\nlogging.config.dictConfig(config)\n\nlogging.getLogger().warning('debug msg')\nprint('in main thread')\n```\n debug msg\n in main thread\n debug msg\n\n</details>\n\n",
"bugtrack_url": null,
"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.",
"summary": "Extensions for the original logging module",
"version": "0.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/jktujg/logging-extension/issues",
"Homepage": "https://github.com/jktujg/logging-extension"
},
"split_keywords": [
"logging",
" formatter",
" handler",
" filter",
" json",
" thread"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7562334f81a0ed46ea4404002b7a25accb09d0a5926be9d383e6efb6e4108d26",
"md5": "d6d5d2f037f56dd5ef9eb05ebfd606d8",
"sha256": "379f8d221ce6abf29d2f8ae2c3a9523b745981dfc44e34d0464fa2fda477164d"
},
"downloads": -1,
"filename": "logging_extension-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d6d5d2f037f56dd5ef9eb05ebfd606d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 6556,
"upload_time": "2024-07-29T13:06:35",
"upload_time_iso_8601": "2024-07-29T13:06:35.707514Z",
"url": "https://files.pythonhosted.org/packages/75/62/334f81a0ed46ea4404002b7a25accb09d0a5926be9d383e6efb6e4108d26/logging_extension-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7b5149a3f8d1c2c2bf5993c47ca4d0e4e4f2665c02d7a3780b8c293b09ac7968",
"md5": "b792ee1b28d2ef3a20366188072a0dbb",
"sha256": "b505298a4065b85e69a68880fdc7c9d38a0f36f402f67324d210a70158743f5b"
},
"downloads": -1,
"filename": "logging_extension-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "b792ee1b28d2ef3a20366188072a0dbb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7348,
"upload_time": "2024-07-29T13:06:36",
"upload_time_iso_8601": "2024-07-29T13:06:36.749655Z",
"url": "https://files.pythonhosted.org/packages/7b/51/49a3f8d1c2c2bf5993c47ca4d0e4e4f2665c02d7a3780b8c293b09ac7968/logging_extension-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-29 13:06:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jktujg",
"github_project": "logging-extension",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "logging-extension"
}