# Pretty Pie Log
A feature-rich, thread-safe Python logging utility that provides colorized console output with customizable formatting,
JSON details support, and function execution tracking.
<div style="display: flex;flex-direction: row;gap: 1rem; justify-content: center; align-items: center;">
<div style="display: flex;">
[![PyPI version](https://badge.fury.io/py/pretty-pie-log.svg)](https://badge.fury.io/py/pretty-pie-log)
</div>
<div style="display: flex;">
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
</div>
</div>
---
## Installation
```bash
pip install pretty-pie-log
```
---
## Features
- **Colorized Output**: Customizable colors for different log levels and components, including `timestamp`, `file path`,
and `details`.
- **Thread-Safe**: Built-in thread safety for reliable logging in multi-threaded applications.
- **Timezone Support**: Configurable timezone for timestamp display (default: UTC).
- **Structured Logging**: JSON formatting for detailed logging information with optional indentation.
- **Automatic Path Detection**: Detects relative file paths based on the project root.
- **Stack Trace Integration**: Optionally include full stack trace details for exceptions.
- **Function Execution Tracking**: Decorator for logging function entry, exit, arguments, and results with configurable
log levels.
- **File Logging**: Configurable rotating file logging with size limits and backup files.
- **Customizable Formatting**: Adjust padding for timestamps, log levels, file paths, and other components.
- **Enhanced Log Details Serialization**: Handles non-serializable objects in logs by converting them into readable
formats.
- **Default Colors and Settings**: New fields for default log colors and detailed customization.
---
## Quick Start
```python
from pretty_pie_log import PieLogger, PieLogLevel
# Create a logger instance
logger = PieLogger(
logger_name="my_app",
timezone="America/New_York", # Optional: Set specific timezone
minimum_log_level=PieLogLevel.INFO, # Optional: Set minimum log level
log_to_file=True, # Optional: Enable file logging
)
# Basic logging methods
logger.info("Application started")
logger.debug("Debug message", details={"user_id": 123})
logger.warning("Warning message")
try:
raise ValueError("Something went wrong")
except ValueError:
logger.error("Error occurred", print_exception=True) # Includes error trace
logger.critical("Critical error", details={"error_code": 500})
# Function execution tracking
@logger.log_execution(
start_message="Starting data processing",
end_message="Processing complete",
print_args_at_start=True,
print_result_at_end=True
)
def process_data(data):
return {"processed": len(data)}
process_data([1, 2, 3, 4, 5])
```
---
## Detailed Configuration
### Logger Initialization
The logger is highly customizable with numerous options:
```python
from pretty_pie_log import PieLogger, PieLogLevel
from colorama import Fore
logger = PieLogger(
logger_name="my_app", # Unique identifier for the logger
# Optional Timezone and Formatting Parameters
timezone="America/New_York", # Defaults to UTC if not specified
timestamp_padding=25, # Width of timestamp field
log_level_padding=10, # Width of log level field
file_path_padding=30, # Width of file path field
# Optional Color Configuration
debug_log_color=Fore.CYAN,
info_log_color=Fore.GREEN,
warning_log_color=Fore.YELLOW,
error_log_color=Fore.RED,
critical_log_color=Fore.MAGENTA,
timestamp_log_color=Fore.WHITE,
file_path_log_color=Fore.WHITE,
details_log_color=Fore.LIGHTWHITE_EX,
# Enhanced Logging Options
colorful=True, # Enable/disable colored output
default_log_color=Fore.WHITE, # Fallback color when colorful is False
details_indent=2, # JSON indentation spaces
minimum_log_level=PieLogLevel.INFO, # Minimum logging level
# Rotating File Logging
log_to_file=True, # Enable/disable file logging
log_directory="logs", # Directory for log files
log_file_size_limit=32 * 1024 * 1024, # Max log file size (32 MB)
max_backup_files=10 # Number of backup log files to keep
)
```
---
## Logging Methods
All logging methods support the following parameters:
```python
logger.info(
message="Main log message", # Required: Main text of the log
details={"key": "value"}, # Optional: Additional data to include (now supports any data type)
print_exception=True, # Optional: Include stack trace if an exception occurred
colorful=False # Optional: Override global color settings for this log
)
```
### Enhanced `details` Parameter
The `details` parameter, which previously supported only `dict`, now supports **any data type**, making it more
versatile for structured and unstructured data logging.
- **Supported Data Types**:
- `dict`: Ideal for key-value pairs or structured data (e.g., `{"user_id": 123, "status": "active"}`)
- `list`/`tuple`: For sequences of data (e.g., `[1, 2, 3]`)
- `set`: For unique collections (e.g., `{"item1", "item2"}`)
- `str`, `int`, `float`, `bool`: Simple data types
- `None`: To explicitly log the absence of details
- **Custom Objects**: Non-serializable objects will automatically be converted into readable strings.
### Example Usage
```python
# Logging structured data
logger.info(
message="User login attempt",
details={"user_id": 123, "status": "success"}
)
# Logging a list of items
logger.debug(
message="Processing items",
details=[1, 2, 3, 4, 5]
)
# Logging a custom object
class User:
def __init__(self, user_id, name):
self.user_id = user_id
self.name = name
def __str__(self):
return f"User(user_id={self.user_id}, name={self.name})"
user = User(123, "John Doe")
logger.warning(
message="Custom object logged",
details=user
)
# Logging without additional details
logger.error(
message="Critical failure occurred",
details=None
)
```
Output:
```text
2024-11-30 10:50:48.966 INFO ./../example.py:16 : User login attempt
{
"user_id": 123,
"status": "success"
}
2024-11-30 10:50:48.968 DEBUG ./../example.py:22 : Processing items
[
1,
2,
3,
4,
5
]
2024-11-30 10:50:48.970 WARNING ./../example.py:38 : Custom object logged
"User(user_id=123, name=John Doe)"
2024-11-30 10:50:48.972 ERROR ./../example.py:44 : Critical failure occurred
```
### Automatic Serialization
If the `details` contain non-serializable objects (e.g., custom classes), the logger will automatically convert them
into strings, ensuring the logs remain readable without raising serialization errors.
### For example:
```python
class ComplexObject:
pass
logger.debug(
message="Logging complex object",
details=ComplexObject()
)
```
### Console Output
```
2024-11-30 10:52:00.125 DEBUG ./../example.py:17 : Logging complex object
"<__main__.ComplexObject object at 0x0000020FD4484A90>"
```
This enhancement ensures compatibility with diverse use cases while maintaining structured logging capabilities.
---
## Log Levels
The package provides five standard log levels:
- `PieLogLevel.DEBUG` (10)
- `PieLogLevel.INFO` (20)
- `PieLogLevel.WARNING` (30)
- `PieLogLevel.ERROR` (40)
- `PieLogLevel.CRITICAL` (50)
---
## Function Execution Tracking
The `log_execution` decorator provides detailed monitoring of function execution:
```python
@logger.log_execution(
start_message="Starting task...", # Optional: Custom start message
end_message="Task complete.", # Optional: Custom end message
print_args_at_start=True, # Log function arguments
print_result_at_end=True, # Log function return values
start_message_log_level=PieLogLevel.DEBUG, # Customizable log levels
end_message_log_level=PieLogLevel.INFO
)
def task(arg1, arg2):
return "result"
```
### Console Output
```text
2024-11-30 10:53:11.645 DEBUG ./../example.py:96 : Starting task...
{
"function": "task",
"args": "('arg1', 'arg2')",
"kwargs": "{}"
}
2024-11-30 10:53:11.647 INFO ./../example.py:96 : Task complete.
{
"function": "task",
"result": "result"
}
```
---
## Dependencies
- Python 3.7+
- colorama
- pytz
---
## Contributing
Contributions are welcome! Submit your ideas or pull requests.
---
## License
[MIT License](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/chanpreet3000/pretty-pie-log",
"name": "pretty-pie-log",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "logging, colorized, console, debug, formatting, pretty-print, thread-safe, timezone, structured-logging",
"author": "chanpreet3000",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/e7/08/80d4bfe9c8b8b854e36c66aa83f25b7c6f71cb5a714acc63fbd41d653d09/pretty_pie_log-0.3.12.tar.gz",
"platform": null,
"description": "# Pretty Pie Log\r\n\r\nA feature-rich, thread-safe Python logging utility that provides colorized console output with customizable formatting,\r\nJSON details support, and function execution tracking.\r\n\r\n<div style=\"display: flex;flex-direction: row;gap: 1rem; justify-content: center; align-items: center;\">\r\n<div style=\"display: flex;\">\r\n\r\n[![PyPI version](https://badge.fury.io/py/pretty-pie-log.svg)](https://badge.fury.io/py/pretty-pie-log)\r\n\r\n</div>\r\n\r\n<div style=\"display: flex;\">\r\n\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n</div>\r\n</div>\r\n\r\n---\r\n\r\n## Installation\r\n\r\n```bash\r\npip install pretty-pie-log\r\n```\r\n\r\n---\r\n\r\n## Features\r\n\r\n- **Colorized Output**: Customizable colors for different log levels and components, including `timestamp`, `file path`,\r\n and `details`.\r\n- **Thread-Safe**: Built-in thread safety for reliable logging in multi-threaded applications.\r\n- **Timezone Support**: Configurable timezone for timestamp display (default: UTC).\r\n- **Structured Logging**: JSON formatting for detailed logging information with optional indentation.\r\n- **Automatic Path Detection**: Detects relative file paths based on the project root.\r\n- **Stack Trace Integration**: Optionally include full stack trace details for exceptions.\r\n- **Function Execution Tracking**: Decorator for logging function entry, exit, arguments, and results with configurable\r\n log levels.\r\n- **File Logging**: Configurable rotating file logging with size limits and backup files.\r\n- **Customizable Formatting**: Adjust padding for timestamps, log levels, file paths, and other components.\r\n- **Enhanced Log Details Serialization**: Handles non-serializable objects in logs by converting them into readable\r\n formats.\r\n- **Default Colors and Settings**: New fields for default log colors and detailed customization.\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom pretty_pie_log import PieLogger, PieLogLevel\r\n\r\n# Create a logger instance\r\nlogger = PieLogger(\r\n logger_name=\"my_app\",\r\n timezone=\"America/New_York\", # Optional: Set specific timezone\r\n minimum_log_level=PieLogLevel.INFO, # Optional: Set minimum log level\r\n log_to_file=True, # Optional: Enable file logging\r\n)\r\n\r\n# Basic logging methods\r\nlogger.info(\"Application started\")\r\nlogger.debug(\"Debug message\", details={\"user_id\": 123})\r\nlogger.warning(\"Warning message\")\r\ntry:\r\n raise ValueError(\"Something went wrong\")\r\nexcept ValueError:\r\n logger.error(\"Error occurred\", print_exception=True) # Includes error trace\r\nlogger.critical(\"Critical error\", details={\"error_code\": 500})\r\n\r\n\r\n# Function execution tracking\r\n@logger.log_execution(\r\n start_message=\"Starting data processing\",\r\n end_message=\"Processing complete\",\r\n print_args_at_start=True,\r\n print_result_at_end=True\r\n)\r\ndef process_data(data):\r\n return {\"processed\": len(data)}\r\n\r\n\r\nprocess_data([1, 2, 3, 4, 5])\r\n```\r\n\r\n---\r\n\r\n## Detailed Configuration\r\n\r\n### Logger Initialization\r\n\r\nThe logger is highly customizable with numerous options:\r\n\r\n```python\r\nfrom pretty_pie_log import PieLogger, PieLogLevel\r\nfrom colorama import Fore\r\n\r\nlogger = PieLogger(\r\n logger_name=\"my_app\", # Unique identifier for the logger\r\n\r\n # Optional Timezone and Formatting Parameters\r\n timezone=\"America/New_York\", # Defaults to UTC if not specified\r\n timestamp_padding=25, # Width of timestamp field\r\n log_level_padding=10, # Width of log level field\r\n file_path_padding=30, # Width of file path field\r\n\r\n # Optional Color Configuration\r\n debug_log_color=Fore.CYAN,\r\n info_log_color=Fore.GREEN,\r\n warning_log_color=Fore.YELLOW,\r\n error_log_color=Fore.RED,\r\n critical_log_color=Fore.MAGENTA,\r\n timestamp_log_color=Fore.WHITE,\r\n file_path_log_color=Fore.WHITE,\r\n details_log_color=Fore.LIGHTWHITE_EX,\r\n\r\n # Enhanced Logging Options\r\n colorful=True, # Enable/disable colored output\r\n default_log_color=Fore.WHITE, # Fallback color when colorful is False\r\n details_indent=2, # JSON indentation spaces\r\n minimum_log_level=PieLogLevel.INFO, # Minimum logging level\r\n\r\n # Rotating File Logging\r\n log_to_file=True, # Enable/disable file logging\r\n log_directory=\"logs\", # Directory for log files\r\n log_file_size_limit=32 * 1024 * 1024, # Max log file size (32 MB)\r\n max_backup_files=10 # Number of backup log files to keep\r\n)\r\n```\r\n\r\n---\r\n\r\n## Logging Methods\r\n\r\nAll logging methods support the following parameters:\r\n\r\n```python\r\nlogger.info(\r\n message=\"Main log message\", # Required: Main text of the log\r\n details={\"key\": \"value\"}, # Optional: Additional data to include (now supports any data type)\r\n print_exception=True, # Optional: Include stack trace if an exception occurred\r\n colorful=False # Optional: Override global color settings for this log\r\n)\r\n```\r\n\r\n### Enhanced `details` Parameter\r\n\r\nThe `details` parameter, which previously supported only `dict`, now supports **any data type**, making it more\r\nversatile for structured and unstructured data logging.\r\n\r\n- **Supported Data Types**:\r\n - `dict`: Ideal for key-value pairs or structured data (e.g., `{\"user_id\": 123, \"status\": \"active\"}`)\r\n - `list`/`tuple`: For sequences of data (e.g., `[1, 2, 3]`)\r\n - `set`: For unique collections (e.g., `{\"item1\", \"item2\"}`)\r\n - `str`, `int`, `float`, `bool`: Simple data types\r\n - `None`: To explicitly log the absence of details\r\n - **Custom Objects**: Non-serializable objects will automatically be converted into readable strings.\r\n\r\n### Example Usage\r\n\r\n```python\r\n# Logging structured data\r\nlogger.info(\r\n message=\"User login attempt\",\r\n details={\"user_id\": 123, \"status\": \"success\"}\r\n)\r\n\r\n# Logging a list of items\r\nlogger.debug(\r\n message=\"Processing items\",\r\n details=[1, 2, 3, 4, 5]\r\n)\r\n\r\n\r\n# Logging a custom object\r\nclass User:\r\n def __init__(self, user_id, name):\r\n self.user_id = user_id\r\n self.name = name\r\n\r\n def __str__(self):\r\n return f\"User(user_id={self.user_id}, name={self.name})\"\r\n\r\n\r\nuser = User(123, \"John Doe\")\r\n\r\nlogger.warning(\r\n message=\"Custom object logged\",\r\n details=user\r\n)\r\n\r\n# Logging without additional details\r\nlogger.error(\r\n message=\"Critical failure occurred\",\r\n details=None\r\n)\r\n```\r\n\r\nOutput:\r\n\r\n```text\r\n2024-11-30 10:50:48.966 INFO ./../example.py:16 : User login attempt\r\n{\r\n \"user_id\": 123,\r\n \"status\": \"success\"\r\n}\r\n2024-11-30 10:50:48.968 DEBUG ./../example.py:22 : Processing items\r\n[\r\n 1,\r\n 2,\r\n 3,\r\n 4,\r\n 5\r\n]\r\n2024-11-30 10:50:48.970 WARNING ./../example.py:38 : Custom object logged\r\n\"User(user_id=123, name=John Doe)\"\r\n2024-11-30 10:50:48.972 ERROR ./../example.py:44 : Critical failure occurred\r\n```\r\n\r\n### Automatic Serialization\r\n\r\nIf the `details` contain non-serializable objects (e.g., custom classes), the logger will automatically convert them\r\ninto strings, ensuring the logs remain readable without raising serialization errors.\r\n\r\n### For example:\r\n\r\n```python\r\nclass ComplexObject:\r\n pass\r\n\r\n\r\nlogger.debug(\r\n message=\"Logging complex object\",\r\n details=ComplexObject()\r\n)\r\n```\r\n\r\n### Console Output\r\n\r\n```\r\n2024-11-30 10:52:00.125 DEBUG ./../example.py:17 : Logging complex object\r\n\"<__main__.ComplexObject object at 0x0000020FD4484A90>\"\r\n```\r\n\r\nThis enhancement ensures compatibility with diverse use cases while maintaining structured logging capabilities.\r\n\r\n---\r\n\r\n## Log Levels\r\n\r\nThe package provides five standard log levels:\r\n\r\n- `PieLogLevel.DEBUG` (10)\r\n- `PieLogLevel.INFO` (20)\r\n- `PieLogLevel.WARNING` (30)\r\n- `PieLogLevel.ERROR` (40)\r\n- `PieLogLevel.CRITICAL` (50)\r\n\r\n---\r\n\r\n## Function Execution Tracking\r\n\r\nThe `log_execution` decorator provides detailed monitoring of function execution:\r\n\r\n```python\r\n@logger.log_execution(\r\n start_message=\"Starting task...\", # Optional: Custom start message\r\n end_message=\"Task complete.\", # Optional: Custom end message\r\n print_args_at_start=True, # Log function arguments\r\n print_result_at_end=True, # Log function return values\r\n start_message_log_level=PieLogLevel.DEBUG, # Customizable log levels\r\n end_message_log_level=PieLogLevel.INFO\r\n)\r\ndef task(arg1, arg2):\r\n return \"result\"\r\n```\r\n\r\n### Console Output\r\n\r\n```text\r\n2024-11-30 10:53:11.645 DEBUG ./../example.py:96 : Starting task...\r\n{\r\n \"function\": \"task\",\r\n \"args\": \"('arg1', 'arg2')\",\r\n \"kwargs\": \"{}\"\r\n}\r\n2024-11-30 10:53:11.647 INFO ./../example.py:96 : Task complete.\r\n{\r\n \"function\": \"task\",\r\n \"result\": \"result\"\r\n}\r\n```\r\n\r\n---\r\n\r\n## Dependencies\r\n\r\n- Python 3.7+\r\n- colorama\r\n- pytz\r\n\r\n---\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Submit your ideas or pull requests.\r\n\r\n---\r\n\r\n## License\r\n\r\n[MIT License](LICENSE)\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A feature-rich logging utility that provides colorized console output with customizable formatting",
"version": "0.3.12",
"project_urls": {
"Bug Tracker": "https://github.com/chanpreet3000/pretty-pie-log/issues",
"Homepage": "https://github.com/chanpreet3000/pretty-pie-log",
"Source Code": "https://github.com/chanpreet3000/pretty-pie-log"
},
"split_keywords": [
"logging",
" colorized",
" console",
" debug",
" formatting",
" pretty-print",
" thread-safe",
" timezone",
" structured-logging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c20c2ac628a2c4ec2a95a37a94c51e9b02765cb22610d0f517fa20d844420a20",
"md5": "909603f83abe9f648964e8528b6bd237",
"sha256": "9c47584b9d0449ad7158d480074be187c8e48fb8d1097cc58feb583ce80f562e"
},
"downloads": -1,
"filename": "pretty_pie_log-0.3.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "909603f83abe9f648964e8528b6bd237",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 10911,
"upload_time": "2024-11-30T10:56:51",
"upload_time_iso_8601": "2024-11-30T10:56:51.616909Z",
"url": "https://files.pythonhosted.org/packages/c2/0c/2ac628a2c4ec2a95a37a94c51e9b02765cb22610d0f517fa20d844420a20/pretty_pie_log-0.3.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e70880d4bfe9c8b8b854e36c66aa83f25b7c6f71cb5a714acc63fbd41d653d09",
"md5": "13b85040b04b2ed3bc2b4ac883886f93",
"sha256": "a56ded17f1d45d8880e2c491cc5c2d6e5956b6f6b091f38f073bff1cc87be70e"
},
"downloads": -1,
"filename": "pretty_pie_log-0.3.12.tar.gz",
"has_sig": false,
"md5_digest": "13b85040b04b2ed3bc2b4ac883886f93",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13196,
"upload_time": "2024-11-30T10:56:58",
"upload_time_iso_8601": "2024-11-30T10:56:58.835801Z",
"url": "https://files.pythonhosted.org/packages/e7/08/80d4bfe9c8b8b854e36c66aa83f25b7c6f71cb5a714acc63fbd41d653d09/pretty_pie_log-0.3.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-30 10:56:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "chanpreet3000",
"github_project": "pretty-pie-log",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pretty-pie-log"
}