![pypi](https://img.shields.io/pypi/v/coloured-logger.svg)
![python](https://img.shields.io/pypi/pyversions/coloured-logger.svg)
![license](https://img.shields.io/github/license/oscar-defelice/coloured-logger.svg)
![last-commit](https://img.shields.io/github/last-commit/oscar-defelice/coloured-logger/develop)
![docs](https://readthedocs.org/projects/coloured-logger/badge/?version=latest)
[![patreon](https://img.shields.io/badge/Patreon-brown.svg?logo=patreon)](https://www.patreon.com/oscardefelice)
[![follow](https://img.shields.io/twitter/follow/oscardefelice.svg?style=social)](https://twitter.com/OscardeFelice)
[![linkedin](https://img.shields.io/badge/LinkedIn-0077B5?&logo=linkedin&logoColor=white)](https://linkedin.com/in/oscar-de-felice)
# ColouredLogger
<!-- markdownlint-disable MD033 -->
<div align="center">
<img src="https://raw.githubusercontent.com/oscar-defelice/coloured-logger/develop/images/logo.png" width="800px">
</div>
<!-- markdownlint-enable MD033 -->
`coloured-logger` is a Python package that provides a customised logger with coloured output and the ability to set verbosity levels dynamically.
## Installation
You can install My Coloured Logger using pip:
```bash
pip install coloured-logger
```
## Usage
As all the good loggers you simply use it as the standard logger
```python
from coloured_logger import Logger
logger = Logger(__name__) # Or any other name you want
logger.info("This is an informational message.")
logger.debug("This debug message won't be displayed.")
```
Colour scheme is customisable by user using the [ANSI escape codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) for colours.
These are typically defined in terms of foreground and background colours, and each color has an associated numeric code. Here is a common mapping:
### Colour codes
Most terminals support 8 and 16 colours, as well as 256 (8-bit) colours. These colours are set by the user, but have commonly defined meanings.
#### 8-16 Colours
| Colour Name | Foreground Colour Code | Background Colour Code |
| :--------- | :-------------------- | :-------------------- |
| Black | `30` | `40` |
| Red | `31` | `41` |
| Green | `32` | `42` |
| Yellow | `33` | `43` |
| Blue | `34` | `44` |
| Magenta | `35` | `45` |
| Cyan | `36` | `46` |
| White | `37` | `47` |
| Default | `39` | `49` |
| Reset | `0` | `0` |
> **Note:** the _Reset_ colour is the reset code that resets _all_ colours and text effects, Use _Default_ colour to reset colours only.
Most terminals, apart from the basic set of 8 colors, also support the "bright" or "bold" colours. These have their own set of codes, mirroring the normal colours, but with an additional `;1` in their codes:
```sh
# Set style to bold, red foreground.
\x1b[1;31mHello
# Set style to dimmed white foreground with red background.
\x1b[2;37;41mWorld
```
### A simplified configuration
The user can simply define a python dictionary in order to change logger colours with a simplified colour scheme.
#### Configure logger colours
In order to configure the logger colours, the user can use the following code
```python
from coloured_logger import Logger
my_custom_colours = {
"WARNING": 4, # Yellow background with blue text
"INFO": 2, # Green text
"DEBUG": 6, # Cyan text
"CRITICAL": 1, # Red text
"ERROR": 5 # Magenta text
}
# This can change the logger level
logger_level = "DEBUG"
logger = Logger(__name__, my_custom_colours, logger_level)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/oscar-defelice/coloured-logger",
"name": "coloured-logger",
"maintainer": "",
"docs_url": null,
"requires_python": ">= 3.9",
"maintainer_email": "",
"keywords": "security,scanner",
"author": "Oscar de Felice",
"author_email": "oscar.defelice@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/10/87/7402c13b137b022360739e35df0f5e078bd4b3199ec119dfe56688328685/coloured-logger-1.0.3.tar.gz",
"platform": null,
"description": "![pypi](https://img.shields.io/pypi/v/coloured-logger.svg)\n![python](https://img.shields.io/pypi/pyversions/coloured-logger.svg)\n![license](https://img.shields.io/github/license/oscar-defelice/coloured-logger.svg)\n![last-commit](https://img.shields.io/github/last-commit/oscar-defelice/coloured-logger/develop)\n![docs](https://readthedocs.org/projects/coloured-logger/badge/?version=latest)\n[![patreon](https://img.shields.io/badge/Patreon-brown.svg?logo=patreon)](https://www.patreon.com/oscardefelice)\n[![follow](https://img.shields.io/twitter/follow/oscardefelice.svg?style=social)](https://twitter.com/OscardeFelice)\n[![linkedin](https://img.shields.io/badge/LinkedIn-0077B5?&logo=linkedin&logoColor=white)](https://linkedin.com/in/oscar-de-felice)\n\n# ColouredLogger\n\n<!-- markdownlint-disable MD033 -->\n<div align=\"center\">\n <img src=\"https://raw.githubusercontent.com/oscar-defelice/coloured-logger/develop/images/logo.png\" width=\"800px\">\n</div>\n<!-- markdownlint-enable MD033 -->\n\n`coloured-logger` is a Python package that provides a customised logger with coloured output and the ability to set verbosity levels dynamically.\n\n## Installation\n\nYou can install My Coloured Logger using pip:\n\n```bash\npip install coloured-logger\n```\n\n## Usage\n\nAs all the good loggers you simply use it as the standard logger\n\n```python\nfrom coloured_logger import Logger\n\nlogger = Logger(__name__) # Or any other name you want\n\nlogger.info(\"This is an informational message.\")\nlogger.debug(\"This debug message won't be displayed.\")\n```\n\nColour scheme is customisable by user using the [ANSI escape codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) for colours.\nThese are typically defined in terms of foreground and background colours, and each color has an associated numeric code. Here is a common mapping:\n\n### Colour codes\n\nMost terminals support 8 and 16 colours, as well as 256 (8-bit) colours. These colours are set by the user, but have commonly defined meanings.\n\n#### 8-16 Colours\n\n| Colour Name | Foreground Colour Code | Background Colour Code |\n| :--------- | :-------------------- | :-------------------- |\n| Black | `30` | `40` |\n| Red | `31` | `41` |\n| Green | `32` | `42` |\n| Yellow | `33` | `43` |\n| Blue | `34` | `44` |\n| Magenta | `35` | `45` |\n| Cyan | `36` | `46` |\n| White | `37` | `47` |\n| Default | `39` | `49` |\n| Reset | `0` | `0` |\n\n> **Note:** the _Reset_ colour is the reset code that resets _all_ colours and text effects, Use _Default_ colour to reset colours only.\n\nMost terminals, apart from the basic set of 8 colors, also support the \"bright\" or \"bold\" colours. These have their own set of codes, mirroring the normal colours, but with an additional `;1` in their codes:\n\n```sh\n# Set style to bold, red foreground.\n\\x1b[1;31mHello\n# Set style to dimmed white foreground with red background.\n\\x1b[2;37;41mWorld\n```\n\n### A simplified configuration\n\nThe user can simply define a python dictionary in order to change logger colours with a simplified colour scheme.\n\n#### Configure logger colours\n\nIn order to configure the logger colours, the user can use the following code\n\n```python\nfrom coloured_logger import Logger\n\nmy_custom_colours = {\n \"WARNING\": 4, # Yellow background with blue text\n \"INFO\": 2, # Green text\n \"DEBUG\": 6, # Cyan text\n \"CRITICAL\": 1, # Red text\n \"ERROR\": 5 # Magenta text\n}\n\n# This can change the logger level\nlogger_level = \"DEBUG\"\n\nlogger = Logger(__name__, my_custom_colours, logger_level)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A coloured logger for Python",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/oscar-defelice/coloured-logger"
},
"split_keywords": [
"security",
"scanner"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "14d79c3540e029f5f0ddda1cac36e74ef33911fc8e143cc150874350c62c8789",
"md5": "bf42349142e9d7af5098ac1b8d674a6f",
"sha256": "b9ded202bdad595afa84f00ddd4f4c5d415e35d772d1f76e710572e7a34c8585"
},
"downloads": -1,
"filename": "coloured_logger-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf42349142e9d7af5098ac1b8d674a6f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">= 3.9",
"size": 6000,
"upload_time": "2023-11-23T12:49:32",
"upload_time_iso_8601": "2023-11-23T12:49:32.494334Z",
"url": "https://files.pythonhosted.org/packages/14/d7/9c3540e029f5f0ddda1cac36e74ef33911fc8e143cc150874350c62c8789/coloured_logger-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "10877402c13b137b022360739e35df0f5e078bd4b3199ec119dfe56688328685",
"md5": "42f436844cfeb689948e21c21ab5b42e",
"sha256": "ba6860028630bb933e0dd1da710e72fdc815906a41701e0cffbad6914848e699"
},
"downloads": -1,
"filename": "coloured-logger-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "42f436844cfeb689948e21c21ab5b42e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">= 3.9",
"size": 5081,
"upload_time": "2023-11-23T12:49:34",
"upload_time_iso_8601": "2023-11-23T12:49:34.065456Z",
"url": "https://files.pythonhosted.org/packages/10/87/7402c13b137b022360739e35df0f5e078bd4b3199ec119dfe56688328685/coloured-logger-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-23 12:49:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oscar-defelice",
"github_project": "coloured-logger",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "coloured-logger"
}