<!--
<p align="center">
<img src="https://github.com/BOHICA-Labs/bohicalog/raw/main/docs/source/logo.png" height="150">
</p>
-->
<h1 align="center">
BOHICA Logging Library
</h1>
<p align="center">
<a href="https://github.com/BOHICA-Labs/bohicalog/actions?query=workflow%3ATests">
<img alt="Tests" src="https://github.com/BOHICA-Labs/bohicalog/workflows/Tests/badge.svg" />
</a>
<a href="https://pypi.org/project/bohicalog">
<img alt="PyPI" src="https://img.shields.io/pypi/v/bohicalog" />
</a>
<a href="https://pypi.org/project/bohicalog">
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/bohicalog" />
</a>
<a href="https://github.com/BOHICA-Labs/bohicalog/blob/main/LICENSE">
<img alt="PyPI - License" src="https://img.shields.io/pypi/l/bohicalog" />
</a>
<a href='https://bohicalog.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/bohicalog/badge/?version=latest' alt='Documentation Status' />
</a>
<a href="https://codecov.io/gh/BOHICA-Labs/bohicalog/branch/main">
<img src="https://codecov.io/gh/BOHICA-Labs/bohicalog/branch/main/graph/badge.svg" alt="Codecov status" />
</a>
<a href="https://github.com/cthoyt/cookiecutter-python-package">
<img alt="Cookiecutter template from @cthoyt" src="https://img.shields.io/badge/Cookiecutter-snekpack-blue" />
</a>
<a href='https://github.com/psf/black'>
<img src='https://img.shields.io/badge/code%20style-black-000000.svg' alt='Code style: black' />
</a>
<a href="https://github.com/BOHICA-Labs/bohicalog/blob/main/.github/CODE_OF_CONDUCT.md">
<img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg" alt="Contributor Covenant"/>
</a>
<a href="https://wakatime.com/projects/bohicalog">
<img src="https://wakatime.com/badge/user/db8a3ca7-6189-459a-a0a4-ba68105a41ee/project/07a61305-1b3b-4cfd-82d8-ba80283fb7b9.svg" alt="Coding Time"/>
</a>
</p>
The BOHICA Logging Library provides a configured logger for you module or application
## 💪 Getting Started
Example Usage
-------------
```python
from bohicalog import logger
logger.debug("hello")
logger.info("info")
logger.warning("warn")
logger.error("error")
# This is how you'd log an exception
try:
raise Exception("this is a demo exception")
except Exception as e:
logger.exception(e)
# JSON logging
import bohicalog
bohicalog.json()
logger.info("JSON test")
# Start writing into a logfile
bohicalog.logfile("/tmp/bohicalog-demo.log")
# Set a minimum loglevel
bohicalog.loglevel(bohicalog.WARNING)
```
This is the output:
![demo-output](https://raw.githubusercontent.com/bohica-labs/bohicalog/master/_static/demo-output-json.png)
Note: You can find more examples in the documentation: https://bohicalog.readthedocs.io
### JSON logging
JSON logging can be enabled for the default logger with `bohicalog.json()`, or with `setup_logger(json=True)` for custom loggers:
```python
>>> bohicalog.json()
>>> logger.info("test")
{"asctime": "2022-12-21 10:42:45,808", "filename": "<stdin>", "funcName": "<module>", "levelname": "INFO", "levelno": 20, "lineno": 1, "module": "<stdin>", "message": "test", "name": "bohicalog_default", "pathname": "<stdin>", "process": 76179, "processName": "MainProcess", "threadName": "MainThread"}
>>> my_logger = setup_logger(json=True)
>>> my_logger.info("test")
{"asctime": "2022-12-21 10:42:45,808", "filename": "<stdin>", "funcName": "<module>", "levelname": "INFO", "levelno": 20, "lineno": 1, "module": "<stdin>", "message": "test", "name": "bohicalog_default", "pathname": "<stdin>", "process": 76179, "processName": "MainProcess", "threadName": "MainThread"}
```
The logged JSON object has these fields:
```json
{
"asctime": "2022-12-21 10:43:40,765",
"filename": "test.py",
"funcName": "test_this",
"levelname": "INFO",
"levelno": 20,
"lineno": 9,
"module": "test",
"message": "info",
"name": "bohicalog",
"pathname": "_tests/test.py",
"process": 76204,
"processName": "MainProcess",
"threadName": "MainThread"
}
```
Exceptions logged with `logger.exception(e)` have these additional JSON fields:
```json
{
"levelname": "ERROR",
"levelno": 40,
"message": "this is a demo exception",
"exc_info": "Traceback (most recent call last):\n File \"_tests/test.py\", line 15, in test_this\n raise Exception(\"this is a demo exception\")\nException: this is a demo exception"
}
```
### Telegram logging
Telegram logging can be enabled for the default logger with `bohicalog.telegram()`, or with `setup_logger(telegram=True)` for custom loggers:
```python
import logging
from bohicalog.handlers import TelegramLoggingHandler
BOT_TOKEN = '1612485124:AAFW9JXxjqY9d-XayMKh8Q4-_iyHkXSw3N8'
CHANNEL_NAME = 'example_channel_logger'
def main():
telegram_log_handler = TelegramLoggingHandler(BOT_TOKEN, CHANNEL_NAME)
my_logger = logging.getLogger('My-Logger')
my_logger.setLevel(logging.INFO)
my_logger.addHandler(logging.StreamHandler())
my_logger.addHandler(telegram_log_handler)
for i in range(5):
my_logger.error(f'iterating {i}..')
if __name__ == '__main__':
main()
```
Take a look at the documentation for more information and examples:
* Documentation: https://bohicalog.readthedocs.io.
## 🚀 Installation
<!-- Uncomment this section after your first ``tox -e finish``
The most recent release can be installed from
[PyPI](https://pypi.org/project/bohicalog/) with:
```bash
$ pip install bohicalog
```
-->
The most recent code and data can be installed directly from GitHub with:
```bash
$ pip install git+https://github.com/BOHICA-Labs/bohicalog.git
```
## 👐 Contributing
Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See
[CONTRIBUTING.md](https://github.com/BOHICA-Labs/bohicalog/blob/master/.github/CONTRIBUTING.md) for more information on getting involved.
## 👋 Attribution
### ⚖️ License
The code in this package is licensed under the MIT License.
<!--
### 📖 Citation
Citation goes here!
-->
<!--
### 🎁 Support
This project has been supported by the following organizations (in alphabetical order):
- [Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/)
-->
<!--
### 💰 Funding
This project has been supported by the following grants:
| Funding Body | Program | Grant |
|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------|
| DARPA | [Automating Scientific Knowledge Extraction (ASKE)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction) | HR00111990009 |
-->
### 🍪 Cookiecutter
This package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s
[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s
[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack) template.
## 🛠️ For Developers
<details>
<summary>See developer instructions</summary>
The final section of the README is for if you want to get involved by making a code contribution.
### Development Installation
To install in development mode, use the following:
```bash
$ git clone git+https://github.com/BOHICA-Labs/bohicalog.git
$ cd bohicalog
$ pip install -e .
```
### 🥼 Testing
After cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be
run reproducibly with:
```shell
$ tox
```
Additionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/BOHICA-Labs/bohicalog/actions?query=workflow%3ATests).
### 📖 Building the Documentation
The documentation can be built locally using the following:
```shell
$ git clone git+https://github.com/BOHICA-Labs/bohicalog.git
$ cd bohicalog
$ tox -e docs
$ open docs/build/html/index.html
```
The documentation automatically installs the package as well as the `docs`
extra specified in the [`setup.cfg`](setup.cfg). `sphinx` plugins
like `texext` can be added there. Additionally, they need to be added to the
`extensions` list in [`docs/source/conf.py`](docs/source/conf.py).
### 📦 Making a Release
After installing the package in development mode and installing
`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment
in `tox.ini`. Run the following from the shell:
```shell
$ tox -e finish
```
This script does the following:
1. Uses [Bump2Version](https://github.com/c4urself/bump2version) to switch the version number in the `setup.cfg`,
`src/bohicalog/version.py`, and [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix
2. Packages the code in both a tar archive and a wheel using [`build`](https://github.com/pypa/build)
3. Uploads to PyPI using [`twine`](https://github.com/pypa/twine). Be sure to have a `.pypirc` file configured to avoid the need for manual input at this
step
4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.
5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can
use `tox -e bumpversion minor` after.
</details>
Raw data
{
"_id": null,
"home_page": "https://github.com/BOHICA-Labs/bohicalog",
"name": "bohicalog",
"maintainer": "Joshua Magady",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "josh.magady@gmail.com",
"keywords": "snekpack,cookiecutter",
"author": "Joshua Magady",
"author_email": "josh.magady@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e9/b2/b66a420c8deab193c406b153801363d84c0e0aba672980555af9deacc566/bohicalog-1.1.3.tar.gz",
"platform": null,
"description": "<!--\n<p align=\"center\">\n <img src=\"https://github.com/BOHICA-Labs/bohicalog/raw/main/docs/source/logo.png\" height=\"150\">\n</p>\n-->\n\n<h1 align=\"center\">\n BOHICA Logging Library\n</h1>\n\n<p align=\"center\">\n <a href=\"https://github.com/BOHICA-Labs/bohicalog/actions?query=workflow%3ATests\">\n <img alt=\"Tests\" src=\"https://github.com/BOHICA-Labs/bohicalog/workflows/Tests/badge.svg\" />\n </a>\n <a href=\"https://pypi.org/project/bohicalog\">\n <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/bohicalog\" />\n </a>\n <a href=\"https://pypi.org/project/bohicalog\">\n <img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/bohicalog\" />\n </a>\n <a href=\"https://github.com/BOHICA-Labs/bohicalog/blob/main/LICENSE\">\n <img alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/bohicalog\" />\n </a>\n <a href='https://bohicalog.readthedocs.io/en/latest/?badge=latest'>\n <img src='https://readthedocs.org/projects/bohicalog/badge/?version=latest' alt='Documentation Status' />\n </a>\n <a href=\"https://codecov.io/gh/BOHICA-Labs/bohicalog/branch/main\">\n <img src=\"https://codecov.io/gh/BOHICA-Labs/bohicalog/branch/main/graph/badge.svg\" alt=\"Codecov status\" />\n </a> \n <a href=\"https://github.com/cthoyt/cookiecutter-python-package\">\n <img alt=\"Cookiecutter template from @cthoyt\" src=\"https://img.shields.io/badge/Cookiecutter-snekpack-blue\" /> \n </a>\n <a href='https://github.com/psf/black'>\n <img src='https://img.shields.io/badge/code%20style-black-000000.svg' alt='Code style: black' />\n </a>\n <a href=\"https://github.com/BOHICA-Labs/bohicalog/blob/main/.github/CODE_OF_CONDUCT.md\">\n <img src=\"https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg\" alt=\"Contributor Covenant\"/>\n </a>\n <a href=\"https://wakatime.com/projects/bohicalog\">\n <img src=\"https://wakatime.com/badge/user/db8a3ca7-6189-459a-a0a4-ba68105a41ee/project/07a61305-1b3b-4cfd-82d8-ba80283fb7b9.svg\" alt=\"Coding Time\"/>\n </a>\n</p>\n\nThe BOHICA Logging Library provides a configured logger for you module or application\n\n## \ud83d\udcaa Getting Started\n\nExample Usage\n-------------\n\n```python\nfrom bohicalog import logger\n\nlogger.debug(\"hello\")\nlogger.info(\"info\")\nlogger.warning(\"warn\")\nlogger.error(\"error\")\n\n# This is how you'd log an exception\ntry:\n raise Exception(\"this is a demo exception\")\nexcept Exception as e:\n logger.exception(e)\n\n# JSON logging\nimport bohicalog\nbohicalog.json()\n\nlogger.info(\"JSON test\")\n\n# Start writing into a logfile\nbohicalog.logfile(\"/tmp/bohicalog-demo.log\")\n\n# Set a minimum loglevel\nbohicalog.loglevel(bohicalog.WARNING)\n```\n\nThis is the output:\n\n![demo-output](https://raw.githubusercontent.com/bohica-labs/bohicalog/master/_static/demo-output-json.png)\n\nNote: You can find more examples in the documentation: https://bohicalog.readthedocs.io\n\n### JSON logging\n\nJSON logging can be enabled for the default logger with `bohicalog.json()`, or with `setup_logger(json=True)` for custom loggers:\n\n```python\n>>> bohicalog.json()\n>>> logger.info(\"test\")\n{\"asctime\": \"2022-12-21 10:42:45,808\", \"filename\": \"<stdin>\", \"funcName\": \"<module>\", \"levelname\": \"INFO\", \"levelno\": 20, \"lineno\": 1, \"module\": \"<stdin>\", \"message\": \"test\", \"name\": \"bohicalog_default\", \"pathname\": \"<stdin>\", \"process\": 76179, \"processName\": \"MainProcess\", \"threadName\": \"MainThread\"}\n\n>>> my_logger = setup_logger(json=True)\n>>> my_logger.info(\"test\")\n{\"asctime\": \"2022-12-21 10:42:45,808\", \"filename\": \"<stdin>\", \"funcName\": \"<module>\", \"levelname\": \"INFO\", \"levelno\": 20, \"lineno\": 1, \"module\": \"<stdin>\", \"message\": \"test\", \"name\": \"bohicalog_default\", \"pathname\": \"<stdin>\", \"process\": 76179, \"processName\": \"MainProcess\", \"threadName\": \"MainThread\"}\n```\n\nThe logged JSON object has these fields:\n\n```json\n{\n \"asctime\": \"2022-12-21 10:43:40,765\",\n \"filename\": \"test.py\",\n \"funcName\": \"test_this\",\n \"levelname\": \"INFO\",\n \"levelno\": 20,\n \"lineno\": 9,\n \"module\": \"test\",\n \"message\": \"info\",\n \"name\": \"bohicalog\",\n \"pathname\": \"_tests/test.py\",\n \"process\": 76204,\n \"processName\": \"MainProcess\",\n \"threadName\": \"MainThread\"\n}\n```\n\nExceptions logged with `logger.exception(e)` have these additional JSON fields:\n\n```json\n{\n \"levelname\": \"ERROR\",\n \"levelno\": 40,\n \"message\": \"this is a demo exception\",\n \"exc_info\": \"Traceback (most recent call last):\\n File \\\"_tests/test.py\\\", line 15, in test_this\\n raise Exception(\\\"this is a demo exception\\\")\\nException: this is a demo exception\"\n}\n```\n\n### Telegram logging\n\nTelegram logging can be enabled for the default logger with `bohicalog.telegram()`, or with `setup_logger(telegram=True)` for custom loggers:\n\n```python\nimport logging\n\nfrom bohicalog.handlers import TelegramLoggingHandler\n\nBOT_TOKEN = '1612485124:AAFW9JXxjqY9d-XayMKh8Q4-_iyHkXSw3N8'\nCHANNEL_NAME = 'example_channel_logger'\n\n\ndef main():\n telegram_log_handler = TelegramLoggingHandler(BOT_TOKEN, CHANNEL_NAME)\n my_logger = logging.getLogger('My-Logger')\n my_logger.setLevel(logging.INFO)\n my_logger.addHandler(logging.StreamHandler())\n my_logger.addHandler(telegram_log_handler)\n\n for i in range(5):\n my_logger.error(f'iterating {i}..')\n\n\nif __name__ == '__main__':\n main()\n```\n\n\nTake a look at the documentation for more information and examples:\n\n* Documentation: https://bohicalog.readthedocs.io.\n\n\n\n## \ud83d\ude80 Installation\n\n<!-- Uncomment this section after your first ``tox -e finish``\nThe most recent release can be installed from\n[PyPI](https://pypi.org/project/bohicalog/) with:\n\n```bash\n$ pip install bohicalog\n```\n-->\n\nThe most recent code and data can be installed directly from GitHub with:\n\n```bash\n$ pip install git+https://github.com/BOHICA-Labs/bohicalog.git\n```\n\n## \ud83d\udc50 Contributing\n\nContributions, whether filing an issue, making a pull request, or forking, are appreciated. See\n[CONTRIBUTING.md](https://github.com/BOHICA-Labs/bohicalog/blob/master/.github/CONTRIBUTING.md) for more information on getting involved.\n\n## \ud83d\udc4b Attribution\n\n### \u2696\ufe0f License\n\nThe code in this package is licensed under the MIT License.\n\n<!--\n### \ud83d\udcd6 Citation\n\nCitation goes here!\n-->\n\n<!--\n### \ud83c\udf81 Support\n\nThis project has been supported by the following organizations (in alphabetical order):\n\n- [Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/)\n\n-->\n\n<!--\n### \ud83d\udcb0 Funding\n\nThis project has been supported by the following grants:\n\n| Funding Body | Program | Grant |\n|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------|\n| DARPA | [Automating Scientific Knowledge Extraction (ASKE)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction) | HR00111990009 |\n-->\n\n### \ud83c\udf6a Cookiecutter\n\nThis package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s\n[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s\n[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack) template.\n\n## \ud83d\udee0\ufe0f For Developers\n\n<details>\n <summary>See developer instructions</summary>\n\n\nThe final section of the README is for if you want to get involved by making a code contribution.\n\n### Development Installation\n\nTo install in development mode, use the following:\n\n```bash\n$ git clone git+https://github.com/BOHICA-Labs/bohicalog.git\n$ cd bohicalog\n$ pip install -e .\n```\n\n### \ud83e\udd7c Testing\n\nAfter cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be\nrun reproducibly with:\n\n```shell\n$ tox\n```\n\nAdditionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/BOHICA-Labs/bohicalog/actions?query=workflow%3ATests).\n\n### \ud83d\udcd6 Building the Documentation\n\nThe documentation can be built locally using the following:\n\n```shell\n$ git clone git+https://github.com/BOHICA-Labs/bohicalog.git\n$ cd bohicalog\n$ tox -e docs\n$ open docs/build/html/index.html\n``` \n\nThe documentation automatically installs the package as well as the `docs`\nextra specified in the [`setup.cfg`](setup.cfg). `sphinx` plugins\nlike `texext` can be added there. Additionally, they need to be added to the\n`extensions` list in [`docs/source/conf.py`](docs/source/conf.py).\n\n### \ud83d\udce6 Making a Release\n\nAfter installing the package in development mode and installing\n`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment\nin `tox.ini`. Run the following from the shell:\n\n```shell\n$ tox -e finish\n```\n\nThis script does the following:\n\n1. Uses [Bump2Version](https://github.com/c4urself/bump2version) to switch the version number in the `setup.cfg`,\n `src/bohicalog/version.py`, and [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix\n2. Packages the code in both a tar archive and a wheel using [`build`](https://github.com/pypa/build)\n3. Uploads to PyPI using [`twine`](https://github.com/pypa/twine). Be sure to have a `.pypirc` file configured to avoid the need for manual input at this\n step\n4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.\n5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can\n use `tox -e bumpversion minor` after.\n</details>\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The BOHICA Logging Library provides a configured logger for you module or application",
"version": "1.1.3",
"split_keywords": [
"snekpack",
"cookiecutter"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f8d0da0fe1dbbf0eb6afe731b2cca2e71d6080b50ca27c4b0040bd70c310d46b",
"md5": "2674c53772b164fd1441a84c96bff0eb",
"sha256": "6099a674c2f09cf0cf3d47eeac6bde07cc81134d21fdade46817b648186f3bea"
},
"downloads": -1,
"filename": "bohicalog-1.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2674c53772b164fd1441a84c96bff0eb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 26037,
"upload_time": "2023-01-04T05:31:39",
"upload_time_iso_8601": "2023-01-04T05:31:39.916700Z",
"url": "https://files.pythonhosted.org/packages/f8/d0/da0fe1dbbf0eb6afe731b2cca2e71d6080b50ca27c4b0040bd70c310d46b/bohicalog-1.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e9b2b66a420c8deab193c406b153801363d84c0e0aba672980555af9deacc566",
"md5": "a536c409a7a5f70094f8aa57d89f3c9b",
"sha256": "d109cd8d6e67eb6310c87b1e6c17212a6aaab8d82c39397a665c9c0a67b481fb"
},
"downloads": -1,
"filename": "bohicalog-1.1.3.tar.gz",
"has_sig": false,
"md5_digest": "a536c409a7a5f70094f8aa57d89f3c9b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 37454,
"upload_time": "2023-01-04T05:31:41",
"upload_time_iso_8601": "2023-01-04T05:31:41.651362Z",
"url": "https://files.pythonhosted.org/packages/e9/b2/b66a420c8deab193c406b153801363d84c0e0aba672980555af9deacc566/bohicalog-1.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-04 05:31:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "BOHICA-Labs",
"github_project": "bohicalog",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "bohicalog"
}