richcolorlog


Namerichcolorlog JSON
Version 1.35 PyPI version JSON
download
home_pagehttps://github.com/cumulus13/richcolorlog
SummaryA beautiful and feature-rich logging package using Rich library
upload_time2025-07-19 14:46:51
maintainerNone
docs_urlNone
authorHadi Cahyadi
requires_python>=3.7
licenseMIT
keywords logging rich console terminal colors formatting
VCS
bugtrack_url
requirements rich
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Rich Color Log

A beautiful and feature-rich logging package using the [Rich](https://github.com/Textualize/rich) library for enhanced console output and file logging.

[![Screenshot](https://raw.githubusercontent.com/cumulus13/richcolorlog/master/screenshot.png)](https://raw.githubusercontent.com/cumulus13/richcolorlog/master/screenshot.png)

## Features

- 🎨 **Beautiful console output** with Rich formatting
- 📝 **Dual logging** - Console and file output simultaneously
- 🎯 **Custom log levels** - EMERGENCY, FATAL, CRITICAL, ALERT, NOTICE
- 🌈 **Syntax highlighting** - Support for code syntax highlighting in logs
- 🔍 **Enhanced tracebacks** - Rich tracebacks with local variables
- ⚙️ **Highly configurable** - Customizable colors, themes, and formats
- 🚀 **Easy to use** - Simple setup with sensible defaults

## Installation

Install from PyPI:

```bash
pip install richcolorlog
```

Or install from source:

```bash
git clone https://github.com/cumulus13/richcolorlog
cd richcolorlog
pip install -e .
```

## Quick Start

### Basic Usage

```python
import logging
from richcolorlog import setup_logging

# Setup the logger use with rich library
logger = setup_logging()

# Use standard logging levels
logger.debug("This is a debug message")
logger.info("This is an info message") 
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")

# Use custom levels
logger.emergency("This is an emergency!")
logger.fatal("This is fatal!")
logger.alert("This is an alert!")
logger.notice("This is a notice")

# Setup the logger use without rich library (ANSI Colors)
logger = setup_logging_custom()
# S/A

```

### Advanced Configuration

#### Using Custom Formatter (rich)

```python
import logging
from richcolorlog import setup_logging

# Setup with custom options
logger = setup_logging(
    show_locals=True,      # Show local variables in tracebacks
    logfile="my_app.log",  # Custom log file name, option default file name [dot] log
    lexer="python",        # Syntax highlighting for Python code, option default None
    level=logging.INFO     # Set minimum log level or just 'INFO'
)

# Log with syntax highlighting
logger.info("Here's some Python code:", extra={"lexer": "python"})
logger.info("def hello_world():\n    print('Hello, World!')")
```

other parameters:

 - show_level: bool = False
 - show_time: bool = True
 - omit_repeated_times: bool = True
 - show_path: bool = True
 - enable_link_path: bool = True
 - highlighter = None
 - markup: bool = False
 - rich_tracebacks: bool = False
 - tracebacks_width: Optional[int] = None
 - tracebacks_extra_lines: int = 3
 - tracebacks_theme: Optional[str] = None
 - tracebacks_word_wrap: bool = True
 - tracebacks_show_locals: bool = False
 - tracebacks_suppress: Iterable[Union[str ModuleType]] = ()
 - locals_max_length: int = 10
 - locals_max_string: int = 80
 - log_time_format: Union[str FormatTimeCallable] = "[%x %X]"
 - keywords: Optional[List[str]] = None
 - show_background = True

#### Using Custom Formatter (ANSI Colors)

```python
from richcolorlog import setup_logging_custom

# Setup basic logging with ANSI color codes
logger = setup_logging_custom()
logger.info("This will be colored in the terminal")
```

other parameters:

 - level = Union[str, int] #example: 'DEBUG' or 'logging.DEBUG'
 - show_background = True
 - format_template=None
 - show_time=True
 - show_name=True
 - show_pid=True
 - show_level=True
 - show_path=True

## Custom Log Levels

Rich Logger adds several custom log levels above the standard CRITICAL level:

| Level | Numeric Value | Description |
|-------|---------------|-------------|
| NOTICE | 55 | Informational messages |
| ALERT | 60 | Alert conditions |
| CRITICAL | 65 | Critical conditions |
| FATAL | 70 | Fatal errors |
| EMERGENCY | 75 | System is unusable |

## Configuration Options

### `setup_logging()`

- `show_locals` (bool): Show local variables in tracebacks (default: False)
- `logfile` (str): Path to log file. Auto-generated if None (default: None)
- `lexer` (str): Syntax highlighter for code blocks (default: None)
- `level` (int): Minimum logging level (default: logging.DEBUG)

### Available Lexers

You can use any lexer supported by Pygments for syntax highlighting:

- `"python"` - Python code
- `"javascript"` - JavaScript code
- `"sql"` - SQL queries  
- `"json"` - JSON data
- `"yaml"` - YAML configuration
- `"bash"` - Shell scripts
- And many more...

## Examples

### Exception Handling with Rich Tracebacks

```python
import logging
from richcolorlog import setup_logging

logger = setup_logging(show_locals=True)

def divide_numbers(a, b):
    try:
        result = a / b
        logger.info(f"Division result: {result}")
        return result
    except ZeroDivisionError:
        logger.exception("Cannot divide by zero!")
        raise

# This will show a beautiful traceback with local variables
divide_numbers(10, 0)
```

### Logging with Context Information

```python
import logging
from richcolorlog import setup_logging, get_def

logger = setup_logging()

class MyClass:
    def my_method(self):
        context = get_def()  # Gets current method/class context
        logger.info(f"{context}Executing method")

obj = MyClass()
obj.my_method()
```

### Code Logging with Syntax Highlighting

```python
import logging
from richcolorlog import setup_logging

logger = setup_logging()

code_snippet = '''
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)
'''

# Log code with Python syntax highlighting
logger.info("Generated function:", extra={"lexer": "python"})
logger.info(code_snippet)
```

## File Structure

When you install this package, your project structure should look like:

```
your_project/
├── your_script.py
├── your_script.log  # Auto-generated log file
└── ...
```

## Requirements

- Python >= 3.7
- rich >= 10.0.0

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- [Rich](https://github.com/Textualize/rich) - For the amazing terminal formatting library
- The Python logging module - For the solid foundation

## author
[Hadi Cahyadi](mailto:cumulus13@gmail.com)
    

[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)

[![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)
 
[Support me on Patreon](https://www.patreon.com/cumulus13)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cumulus13/richcolorlog",
    "name": "richcolorlog",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Hadi Cahyadi <cumulus13@gmail.com>",
    "keywords": "logging, rich, console, terminal, colors, formatting",
    "author": "Hadi Cahyadi",
    "author_email": "Hadi Cahyadi <cumulus13@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fc/b8/4fc2dbbbd4dc9e5d7c3dc25325596a5ab9d244adad85f8590ffce4b236b2/richcolorlog-1.35.tar.gz",
    "platform": null,
    "description": "# Rich Color Log\r\n\r\nA beautiful and feature-rich logging package using the [Rich](https://github.com/Textualize/rich) library for enhanced console output and file logging.\r\n\r\n[![Screenshot](https://raw.githubusercontent.com/cumulus13/richcolorlog/master/screenshot.png)](https://raw.githubusercontent.com/cumulus13/richcolorlog/master/screenshot.png)\r\n\r\n## Features\r\n\r\n- \ud83c\udfa8 **Beautiful console output** with Rich formatting\r\n- \ud83d\udcdd **Dual logging** - Console and file output simultaneously\r\n- \ud83c\udfaf **Custom log levels** - EMERGENCY, FATAL, CRITICAL, ALERT, NOTICE\r\n- \ud83c\udf08 **Syntax highlighting** - Support for code syntax highlighting in logs\r\n- \ud83d\udd0d **Enhanced tracebacks** - Rich tracebacks with local variables\r\n- \u2699\ufe0f **Highly configurable** - Customizable colors, themes, and formats\r\n- \ud83d\ude80 **Easy to use** - Simple setup with sensible defaults\r\n\r\n## Installation\r\n\r\nInstall from PyPI:\r\n\r\n```bash\r\npip install richcolorlog\r\n```\r\n\r\nOr install from source:\r\n\r\n```bash\r\ngit clone https://github.com/cumulus13/richcolorlog\r\ncd richcolorlog\r\npip install -e .\r\n```\r\n\r\n## Quick Start\r\n\r\n### Basic Usage\r\n\r\n```python\r\nimport logging\r\nfrom richcolorlog import setup_logging\r\n\r\n# Setup the logger use with rich library\r\nlogger = setup_logging()\r\n\r\n# Use standard logging levels\r\nlogger.debug(\"This is a debug message\")\r\nlogger.info(\"This is an info message\") \r\nlogger.warning(\"This is a warning message\")\r\nlogger.error(\"This is an error message\")\r\nlogger.critical(\"This is a critical message\")\r\n\r\n# Use custom levels\r\nlogger.emergency(\"This is an emergency!\")\r\nlogger.fatal(\"This is fatal!\")\r\nlogger.alert(\"This is an alert!\")\r\nlogger.notice(\"This is a notice\")\r\n\r\n# Setup the logger use without rich library (ANSI Colors)\r\nlogger = setup_logging_custom()\r\n# S/A\r\n\r\n```\r\n\r\n### Advanced Configuration\r\n\r\n#### Using Custom Formatter (rich)\r\n\r\n```python\r\nimport logging\r\nfrom richcolorlog import setup_logging\r\n\r\n# Setup with custom options\r\nlogger = setup_logging(\r\n    show_locals=True,      # Show local variables in tracebacks\r\n    logfile=\"my_app.log\",  # Custom log file name, option default file name [dot] log\r\n    lexer=\"python\",        # Syntax highlighting for Python code, option default None\r\n    level=logging.INFO     # Set minimum log level or just 'INFO'\r\n)\r\n\r\n# Log with syntax highlighting\r\nlogger.info(\"Here's some Python code:\", extra={\"lexer\": \"python\"})\r\nlogger.info(\"def hello_world():\\n    print('Hello, World!')\")\r\n```\r\n\r\nother parameters:\r\n\r\n - show_level: bool = False\r\n - show_time: bool = True\r\n - omit_repeated_times: bool = True\r\n - show_path: bool = True\r\n - enable_link_path: bool = True\r\n - highlighter = None\r\n - markup: bool = False\r\n - rich_tracebacks: bool = False\r\n - tracebacks_width: Optional[int] = None\r\n - tracebacks_extra_lines: int = 3\r\n - tracebacks_theme: Optional[str] = None\r\n - tracebacks_word_wrap: bool = True\r\n - tracebacks_show_locals: bool = False\r\n - tracebacks_suppress: Iterable[Union[str ModuleType]] = ()\r\n - locals_max_length: int = 10\r\n - locals_max_string: int = 80\r\n - log_time_format: Union[str FormatTimeCallable] = \"[%x %X]\"\r\n - keywords: Optional[List[str]] = None\r\n - show_background = True\r\n\r\n#### Using Custom Formatter (ANSI Colors)\r\n\r\n```python\r\nfrom richcolorlog import setup_logging_custom\r\n\r\n# Setup basic logging with ANSI color codes\r\nlogger = setup_logging_custom()\r\nlogger.info(\"This will be colored in the terminal\")\r\n```\r\n\r\nother parameters:\r\n\r\n - level = Union[str, int] #example: 'DEBUG' or 'logging.DEBUG'\r\n - show_background = True\r\n - format_template=None\r\n - show_time=True\r\n - show_name=True\r\n - show_pid=True\r\n - show_level=True\r\n - show_path=True\r\n\r\n## Custom Log Levels\r\n\r\nRich Logger adds several custom log levels above the standard CRITICAL level:\r\n\r\n| Level | Numeric Value | Description |\r\n|-------|---------------|-------------|\r\n| NOTICE | 55 | Informational messages |\r\n| ALERT | 60 | Alert conditions |\r\n| CRITICAL | 65 | Critical conditions |\r\n| FATAL | 70 | Fatal errors |\r\n| EMERGENCY | 75 | System is unusable |\r\n\r\n## Configuration Options\r\n\r\n### `setup_logging()`\r\n\r\n- `show_locals` (bool): Show local variables in tracebacks (default: False)\r\n- `logfile` (str): Path to log file. Auto-generated if None (default: None)\r\n- `lexer` (str): Syntax highlighter for code blocks (default: None)\r\n- `level` (int): Minimum logging level (default: logging.DEBUG)\r\n\r\n### Available Lexers\r\n\r\nYou can use any lexer supported by Pygments for syntax highlighting:\r\n\r\n- `\"python\"` - Python code\r\n- `\"javascript\"` - JavaScript code\r\n- `\"sql\"` - SQL queries  \r\n- `\"json\"` - JSON data\r\n- `\"yaml\"` - YAML configuration\r\n- `\"bash\"` - Shell scripts\r\n- And many more...\r\n\r\n## Examples\r\n\r\n### Exception Handling with Rich Tracebacks\r\n\r\n```python\r\nimport logging\r\nfrom richcolorlog import setup_logging\r\n\r\nlogger = setup_logging(show_locals=True)\r\n\r\ndef divide_numbers(a, b):\r\n    try:\r\n        result = a / b\r\n        logger.info(f\"Division result: {result}\")\r\n        return result\r\n    except ZeroDivisionError:\r\n        logger.exception(\"Cannot divide by zero!\")\r\n        raise\r\n\r\n# This will show a beautiful traceback with local variables\r\ndivide_numbers(10, 0)\r\n```\r\n\r\n### Logging with Context Information\r\n\r\n```python\r\nimport logging\r\nfrom richcolorlog import setup_logging, get_def\r\n\r\nlogger = setup_logging()\r\n\r\nclass MyClass:\r\n    def my_method(self):\r\n        context = get_def()  # Gets current method/class context\r\n        logger.info(f\"{context}Executing method\")\r\n\r\nobj = MyClass()\r\nobj.my_method()\r\n```\r\n\r\n### Code Logging with Syntax Highlighting\r\n\r\n```python\r\nimport logging\r\nfrom richcolorlog import setup_logging\r\n\r\nlogger = setup_logging()\r\n\r\ncode_snippet = '''\r\ndef fibonacci(n):\r\n    if n <= 1:\r\n        return n\r\n    return fibonacci(n-1) + fibonacci(n-2)\r\n'''\r\n\r\n# Log code with Python syntax highlighting\r\nlogger.info(\"Generated function:\", extra={\"lexer\": \"python\"})\r\nlogger.info(code_snippet)\r\n```\r\n\r\n## File Structure\r\n\r\nWhen you install this package, your project structure should look like:\r\n\r\n```\r\nyour_project/\r\n\u251c\u2500\u2500 your_script.py\r\n\u251c\u2500\u2500 your_script.log  # Auto-generated log file\r\n\u2514\u2500\u2500 ...\r\n```\r\n\r\n## Requirements\r\n\r\n- Python >= 3.7\r\n- rich >= 10.0.0\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Acknowledgments\r\n\r\n- [Rich](https://github.com/Textualize/rich) - For the amazing terminal formatting library\r\n- The Python logging module - For the solid foundation\r\n\r\n## author\r\n[Hadi Cahyadi](mailto:cumulus13@gmail.com)\r\n    \r\n\r\n[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)\r\n\r\n[![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)\r\n \r\n[Support me on Patreon](https://www.patreon.com/cumulus13)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A beautiful and feature-rich logging package using Rich library",
    "version": "1.35",
    "project_urls": {
        "Bug Tracker": "https://github.com/cumulus13/richcolorlog/issues",
        "Documentation": "https://github.com/cumulus13/richcolorlog#readme",
        "Homepage": "https://github.com/cumulus13/richcolorlog",
        "Repository": "https://github.com/cumulus13/richcolorlog"
    },
    "split_keywords": [
        "logging",
        " rich",
        " console",
        " terminal",
        " colors",
        " formatting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "359dbcba577d0ebaaa2ecc14576a4bf519016e2c3989797cfab3eccc377c29a5",
                "md5": "1fa283d72323dd42c8b8b24f7c2a07fb",
                "sha256": "2dcae0c9c06840513f151faa12dcd749eab03609d98bc3c7c4db23bf92607099"
            },
            "downloads": -1,
            "filename": "richcolorlog-1.35-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1fa283d72323dd42c8b8b24f7c2a07fb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 112178,
            "upload_time": "2025-07-19T14:46:47",
            "upload_time_iso_8601": "2025-07-19T14:46:47.283258Z",
            "url": "https://files.pythonhosted.org/packages/35/9d/bcba577d0ebaaa2ecc14576a4bf519016e2c3989797cfab3eccc377c29a5/richcolorlog-1.35-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fcb84fc2dbbbd4dc9e5d7c3dc25325596a5ab9d244adad85f8590ffce4b236b2",
                "md5": "2dc664097b875df191090552bc70091d",
                "sha256": "236f1f2a9ee9f304b2fad51559191a7d95df9966a21929750bdce5ade2db9c26"
            },
            "downloads": -1,
            "filename": "richcolorlog-1.35.tar.gz",
            "has_sig": false,
            "md5_digest": "2dc664097b875df191090552bc70091d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 217556,
            "upload_time": "2025-07-19T14:46:51",
            "upload_time_iso_8601": "2025-07-19T14:46:51.453869Z",
            "url": "https://files.pythonhosted.org/packages/fc/b8/4fc2dbbbd4dc9e5d7c3dc25325596a5ab9d244adad85f8590ffce4b236b2/richcolorlog-1.35.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-19 14:46:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cumulus13",
    "github_project": "richcolorlog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "rich",
            "specs": [
                [
                    ">=",
                    "10.0.0"
                ]
            ]
        }
    ],
    "lcname": "richcolorlog"
}
        
Elapsed time: 1.47035s