# netlink-logging
_Part of the NetLink Python Tools_
A small wrapper around python logging and [logzero](https://logzero.readthedocs.io/en/latest/).
## Features
- Log to a logfile automatically (same name as the top-level script, `_input_` for console)
- Additional levels:
- `TRACE` (`5`)
- `VERBOSE` (`15`)
- `SUCCESS` (`25`)
- Timestamps are in UTC and use format `%Y-%m-%d %H:%M:%S`
- Uncaught Exceptions are logged as `CRITICAL`
## Installation
```bash
pip install netlink-logging
```
## Usage
```python
from netlink.logging import logger
logger.trace('A TRACE entry.')
logger.debug('A DEBUG entry.')
logger.verbose('A VERBOSE entry.')
logger.info('An INFO entry.')
logger.success('A SUCCESS entry.')
logger.warning('A WARNING entry.')
logger.error('An ERROR entry.')
logger.critical('A CRITICAL entry.')
```
results in
```
[D 2022-02-32 26:27:28 <input>:…] A DEBUG entry.
[V 2022-02-32 26:27:28 <input>:…] A VERBOSE entry.
[I 2022-02-32 26:27:28 <input>:…] An INFO entry.
[S 2022-02-32 26:27:28 <input>:…] A SUCCESS entry.
[W 2022-02-32 26:27:28 <input>:…] A WARNING entry.
[E 2022-02-32 26:27:28 <input>:…] An ERROR entry.
[C 2022-02-32 26:27:28 <input>:…] A CRITICAL entry.
```
## Additional Methods
### `set_file`
Use `set_file` to change the file that is logged to:
```
logger.set_file([filename,
[formatter,]
[mode,]
[max_bytes,]
[backup_count,]
[encoding,]
[log_level,]
[disable_stderr_logger]])
```
#### Parameters
- **filename** (optional, `str`)
Must be provided, if any other parameter is provided. If not provided, or set to `None` logging to file is disabled.
- **formatter** (optional, `logging.Formatter`)
Formatter to use for logging to file. Defaults to `[K time module:line number] (message`, where
- **K** is the first letter of the logging level
- **time** is `%Y-%m-%d %H:%M:%S` in UTC
- **module** and **line number show the location in code
- **message** as provided in call
- **mode** (optional, `str`)
Mode to open the file with. Defaults to `a`.
- **max_bytes** (optional, `int`)
Size of the logfile when rollover should occur. If set to `0`, rollover never occurs. Defaults to `100 MB`.
- **backup_count** (optional, `int`)
Number of backups to keep. If set to 0, rollover never occurs. Defaults to `5`.
- **encoding** (optional, `str`)
Used to open the file with that encoding. Defaults to `utf-8`.
- **log_level** (optional, `int`)
Set a custom logging level for the file logger. Defaults to the current logging level.
- **disable_stderr_logger** (optional, `bool`)
Should the default stderr logger be disabled. Defaults to `False`.
### `set_level`
The current logging level can be set without additional imports:
```python
from netlink.logging import logger
logger.set_level(logger.ERROR)
```
### `enable_file`
Enable logging to file, if it was disabled. Takes _boolean_.
### `disable_file`
Disable logging to file.
### `hide_location`
Hide module name and line number.
### `show_threading`
Show thread name.
### `hide_threading`
Hide thread name.
## Changes
### 0.1.10
Option to show or hide thread name
## Roadmap
An additional feature that is considered would log **every** Exception raised.
## License
### MIT License
Copyright (c) 2022 Bernhard Radermacher
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.
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/netlink-consulting/netlink-logging",
"name": "netlink-logging",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<3.13",
"maintainer_email": "",
"keywords": "logging",
"author": "Bernhard Radermacher",
"author_email": "bernhard.radermacher@netlink-consulting.com",
"download_url": "https://files.pythonhosted.org/packages/e2/7c/f737bd9dd6b573b7dc5e9825ab8717a2e66cf68108e4b63b40c9eb6c7cbc/netlink-logging-0.1.14.tar.gz",
"platform": null,
"description": "# netlink-logging\n\n_Part of the NetLink Python Tools_\n\nA small wrapper around python logging and [logzero](https://logzero.readthedocs.io/en/latest/).\n\n## Features\n\n- Log to a logfile automatically (same name as the top-level script, `_input_` for console)\n- Additional levels:\n - `TRACE` (`5`)\n - `VERBOSE` (`15`)\n - `SUCCESS` (`25`)\n- Timestamps are in UTC and use format `%Y-%m-%d %H:%M:%S`\n- Uncaught Exceptions are logged as `CRITICAL`\n\n## Installation\n\n```bash\npip install netlink-logging\n```\n\n## Usage\n\n```python\nfrom netlink.logging import logger \n\nlogger.trace('A TRACE entry.')\nlogger.debug('A DEBUG entry.')\nlogger.verbose('A VERBOSE entry.')\nlogger.info('An INFO entry.')\nlogger.success('A SUCCESS entry.')\nlogger.warning('A WARNING entry.')\nlogger.error('An ERROR entry.')\nlogger.critical('A CRITICAL entry.')\n```\n\nresults in\n\n``` \n[D 2022-02-32 26:27:28 <input>:\u2026] A DEBUG entry.\n[V 2022-02-32 26:27:28 <input>:\u2026] A VERBOSE entry.\n[I 2022-02-32 26:27:28 <input>:\u2026] An INFO entry.\n[S 2022-02-32 26:27:28 <input>:\u2026] A SUCCESS entry.\n[W 2022-02-32 26:27:28 <input>:\u2026] A WARNING entry.\n[E 2022-02-32 26:27:28 <input>:\u2026] An ERROR entry.\n[C 2022-02-32 26:27:28 <input>:\u2026] A CRITICAL entry.\n```\n\n## Additional Methods\n\n### `set_file`\n\nUse `set_file` to change the file that is logged to:\n\n```\nlogger.set_file([filename, \n [formatter,] \n [mode,] \n [max_bytes,] \n [backup_count,] \n [encoding,] \n [log_level,] \n [disable_stderr_logger]])\n```\n\n#### Parameters\n\n- **filename** (optional, `str`)\n\n Must be provided, if any other parameter is provided. If not provided, or set to `None` logging to file is disabled.\n\n- **formatter** (optional, `logging.Formatter`)\n \n Formatter to use for logging to file. Defaults to `[K time module:line number] (message`, where \n - **K** is the first letter of the logging level\n - **time** is `%Y-%m-%d %H:%M:%S` in UTC\n - **module** and **line number show the location in code\n - **message** as provided in call\n\n- **mode** (optional, `str`)\n\n Mode to open the file with. Defaults to `a`.\n\n- **max_bytes** (optional, `int`)\n \n Size of the logfile when rollover should occur. If set to `0`, rollover never occurs. Defaults to `100 MB`. \n\n- **backup_count** (optional, `int`)\n\n Number of backups to keep. If set to 0, rollover never occurs. Defaults to `5`.\n\n- **encoding** (optional, `str`)\n \n Used to open the file with that encoding. Defaults to `utf-8`.\n\n- **log_level** (optional, `int`)\n\n Set a custom logging level for the file logger. Defaults to the current logging level.\n\n- **disable_stderr_logger** (optional, `bool`)\n\n Should the default stderr logger be disabled. Defaults to `False`.\n\n\n### `set_level`\n\nThe current logging level can be set without additional imports:\n\n```python\nfrom netlink.logging import logger\n\nlogger.set_level(logger.ERROR)\n```\n\n### `enable_file`\n\nEnable logging to file, if it was disabled. Takes _boolean_.\n\n### `disable_file`\n\nDisable logging to file.\n\n### `hide_location`\n\nHide module name and line number.\n\n### `show_threading`\n\nShow thread name.\n\n### `hide_threading`\n\nHide thread name.\n\n\n## Changes\n\n### 0.1.10\n\nOption to show or hide thread name\n\n## Roadmap\n\nAn additional feature that is considered would log **every** Exception raised.\n\n## License\n\n### MIT License\n\nCopyright (c) 2022 Bernhard Radermacher\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A wrapper around logging and logzero",
"version": "0.1.14",
"project_urls": {
"Homepage": "https://gitlab.com/netlink-consulting/netlink-logging",
"Repository": "https://gitlab.com/netlink-consulting/netlink-logging"
},
"split_keywords": [
"logging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "770b4f2b6f5ace1d0eb113bc90d2d17acfb08fdcbc22beee31d1e3fea8ba846f",
"md5": "73d7575155501e230a1af10aa740015f",
"sha256": "6f5a0d2492ca35aeff045d26c2401803ac42ce524caedb22cf7226030e85a20e"
},
"downloads": -1,
"filename": "netlink_logging-0.1.14-py3-none-any.whl",
"has_sig": false,
"md5_digest": "73d7575155501e230a1af10aa740015f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<3.13",
"size": 6448,
"upload_time": "2023-11-17T07:56:42",
"upload_time_iso_8601": "2023-11-17T07:56:42.377115Z",
"url": "https://files.pythonhosted.org/packages/77/0b/4f2b6f5ace1d0eb113bc90d2d17acfb08fdcbc22beee31d1e3fea8ba846f/netlink_logging-0.1.14-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e27cf737bd9dd6b573b7dc5e9825ab8717a2e66cf68108e4b63b40c9eb6c7cbc",
"md5": "50bb62c2d7303b953b6226d2ec9914b6",
"sha256": "ba7939218733b3c945cbee1b6d41f013995ac1fba880fa225bdf45f044542864"
},
"downloads": -1,
"filename": "netlink-logging-0.1.14.tar.gz",
"has_sig": false,
"md5_digest": "50bb62c2d7303b953b6226d2ec9914b6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<3.13",
"size": 5789,
"upload_time": "2023-11-17T07:56:40",
"upload_time_iso_8601": "2023-11-17T07:56:40.952967Z",
"url": "https://files.pythonhosted.org/packages/e2/7c/f737bd9dd6b573b7dc5e9825ab8717a2e66cf68108e4b63b40c9eb6c7cbc/netlink-logging-0.1.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-17 07:56:40",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "netlink-consulting",
"gitlab_project": "netlink-logging",
"lcname": "netlink-logging"
}