Name | sharklog JSON |
Version |
0.0.7
JSON |
| download |
home_page | None |
Summary | A Python logging helper |
upload_time | 2024-12-18 06:32:11 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License Copyright (c) 2024 ShiChangshan 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
helper
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# sharklog
Python logging helper.
[![PyPI License](https://img.shields.io/pypi/l/sharklog.svg)](https://pypi.org/project/sharklog)
[![PyPI Version](https://img.shields.io/pypi/v/sharklog.svg)](https://pypi.org/project/sharklog)
## Quick Start
- Install sharklog:
```bash
python3 -m pip install sharklog
```
- Use in standalone script:
```python
# standalone.py
import sharklog
sharklog.init(debug=True) # init current logger with level=sharklog.DEBUG
sharklog.debug("debug message")
sharklog.info("info message")
sharklog.warning("warning message")
sharklog.error("error message")
```
The default format of log messages is:
```python
"[%(levelname)s]: %(message)s [%(asctime)s](%(filename)s:%(lineno)d)"
```
## Usage
### Use in standalone script
If you want to change logging level for a module, you can set it in the module by:
```python
import sharklog
sharklog.getLogger().setLevel(logging.DEBUG)
```
or set it outside the module by specifying the logger name:
```python
import sharklog
sharklog.getLogger("module_name").setLevel(logging.DEBUG)
```
### Usage in Package Development
Now I assume your file structure is like this:
```bash
--- parent_package
|--- __init__.py
|--- parent_module.py
|--- logger.py
|--- sub_package
|--- __init__.py
|--- sub_module.py
```
- First, you can add `NullHandler` to the root logger in `parent_package/__init__.py`, which logger named `parent_package`:
```python
# parent/__init__.py
from sharklog import logging
logging.getLogger().addHandler(logging.NullHandler())
```
This is mentioned in the [Python Logging HOWTO](https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library) to identify the logger's default behavior.
- Then, use `logging` in your package, they will be prefixed with the logger name `parent_package.`:
```python
# parent_module.py which is placed under package `parent_package`
from sharklog import logging
logger = logging.getLogger() # the logger name will be `parent_package.parent_module`
logger.debug("debug message")
logger.info("info message")
logger.warning("warning message")
logger.error("error message")
```
If you already using builtin logging module, you can use sharklog as a drop-in replacement.
Just change ~~`import logging`~~ into `from sharklog import logging`. Then you can use `logging` as usual:
```python
# sub_module.py
from sharklog import logging
# these log messages will be prefixed with the logger name `xxxpackage.xxmodule.module_name`
# here, as an example, the logger name will be `parent_package.sub_package.sub_module`
logging.debug("debug message")
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
```
- Finally, you can set the logging level for the package in the main script which using the package:
```python
# main.py
from sharklog import logging
from parent_package import parent_module
from parent_package.sub_package import sub_module
if __name__ == "__main__":
logging.init(debug=True) # init current logger with level=logging.DEBUG
# or logging.init(level=logging.DEBUG)
# logging inside the package will use the level set here
```
Or if you want to change the logging level for a specific module, you can set it in the module by:
```python
from sharklog import logging
logging.getLogger().setLevel(logging.WARNING)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "sharklog",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "logging, helper",
"author": null,
"author_email": "Shi Changshan <changshanshi@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/b5/47/546e82fc3c924450868a596a89bcd39cf1b6690f7dafb0e254641866c27f/sharklog-0.0.7.tar.gz",
"platform": null,
"description": "# sharklog\n\nPython logging helper.\n\n[![PyPI License](https://img.shields.io/pypi/l/sharklog.svg)](https://pypi.org/project/sharklog)\n[![PyPI Version](https://img.shields.io/pypi/v/sharklog.svg)](https://pypi.org/project/sharklog)\n\n## Quick Start\n\n- Install sharklog:\n\n```bash\npython3 -m pip install sharklog\n```\n\n- Use in standalone script:\n\n```python\n# standalone.py\nimport sharklog\n\nsharklog.init(debug=True) # init current logger with level=sharklog.DEBUG\n\nsharklog.debug(\"debug message\")\nsharklog.info(\"info message\")\nsharklog.warning(\"warning message\")\nsharklog.error(\"error message\")\n```\n\nThe default format of log messages is:\n\n```python\n\"[%(levelname)s]: %(message)s [%(asctime)s](%(filename)s:%(lineno)d)\"\n```\n\n## Usage\n\n### Use in standalone script\n\nIf you want to change logging level for a module, you can set it in the module by:\n\n```python\nimport sharklog\nsharklog.getLogger().setLevel(logging.DEBUG)\n```\n\nor set it outside the module by specifying the logger name:\n\n```python\nimport sharklog\nsharklog.getLogger(\"module_name\").setLevel(logging.DEBUG)\n```\n\n### Usage in Package Development\n\nNow I assume your file structure is like this:\n\n```bash\n--- parent_package\n |--- __init__.py\n |--- parent_module.py\n |--- logger.py\n |--- sub_package\n |--- __init__.py\n |--- sub_module.py\n```\n\n- First, you can add `NullHandler` to the root logger in `parent_package/__init__.py`, which logger named `parent_package`:\n\n```python\n# parent/__init__.py\nfrom sharklog import logging\n\nlogging.getLogger().addHandler(logging.NullHandler())\n```\n\nThis is mentioned in the [Python Logging HOWTO](https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library) to identify the logger's default behavior.\n\n- Then, use `logging` in your package, they will be prefixed with the logger name `parent_package.`:\n\n```python\n# parent_module.py which is placed under package `parent_package`\nfrom sharklog import logging\n\nlogger = logging.getLogger() # the logger name will be `parent_package.parent_module`\n\nlogger.debug(\"debug message\")\nlogger.info(\"info message\")\nlogger.warning(\"warning message\")\nlogger.error(\"error message\")\n```\n\nIf you already using builtin logging module, you can use sharklog as a drop-in replacement.\n\nJust change ~~`import logging`~~ into `from sharklog import logging`. Then you can use `logging` as usual:\n\n```python\n# sub_module.py\nfrom sharklog import logging\n\n# these log messages will be prefixed with the logger name `xxxpackage.xxmodule.module_name`\n# here, as an example, the logger name will be `parent_package.sub_package.sub_module`\nlogging.debug(\"debug message\")\nlogging.info(\"info message\")\nlogging.warning(\"warning message\")\nlogging.error(\"error message\")\n```\n\n- Finally, you can set the logging level for the package in the main script which using the package:\n\n```python\n# main.py\nfrom sharklog import logging\n\nfrom parent_package import parent_module\nfrom parent_package.sub_package import sub_module\n\nif __name__ == \"__main__\":\n logging.init(debug=True) # init current logger with level=logging.DEBUG\n # or logging.init(level=logging.DEBUG)\n # logging inside the package will use the level set here\n```\n\nOr if you want to change the logging level for a specific module, you can set it in the module by:\n\n```python\nfrom sharklog import logging\nlogging.getLogger().setLevel(logging.WARNING)\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 ShiChangshan 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": "A Python logging helper",
"version": "0.0.7",
"project_urls": {
"Homepage": "https://github.com/Bardreamaster/sharklog"
},
"split_keywords": [
"logging",
" helper"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "491561bf784aeb69938bc19737e6f4e1278c0b69dc43d2d63d66552007b0313a",
"md5": "bb9e79a67ce6965560ad0588f56f90fa",
"sha256": "0b857f6037c0c7dc70f06380bc0ec58834db84c47002593a504b519e6eec14cc"
},
"downloads": -1,
"filename": "sharklog-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bb9e79a67ce6965560ad0588f56f90fa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6370,
"upload_time": "2024-12-18T06:32:07",
"upload_time_iso_8601": "2024-12-18T06:32:07.556180Z",
"url": "https://files.pythonhosted.org/packages/49/15/61bf784aeb69938bc19737e6f4e1278c0b69dc43d2d63d66552007b0313a/sharklog-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b547546e82fc3c924450868a596a89bcd39cf1b6690f7dafb0e254641866c27f",
"md5": "ccbd9685b70a71ac7c42cf833a58b8a7",
"sha256": "520e01fd87de7aab1a57bfeecb194328b7c1e016ac62a8475a60b1075e13c68c"
},
"downloads": -1,
"filename": "sharklog-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "ccbd9685b70a71ac7c42cf833a58b8a7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5852,
"upload_time": "2024-12-18T06:32:11",
"upload_time_iso_8601": "2024-12-18T06:32:11.170843Z",
"url": "https://files.pythonhosted.org/packages/b5/47/546e82fc3c924450868a596a89bcd39cf1b6690f7dafb0e254641866c27f/sharklog-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-18 06:32:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Bardreamaster",
"github_project": "sharklog",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sharklog"
}