# Wise Print
<p align="left">
<a href="https://pypi.python.org/pypi/wise_print"><img alt="PyPI" src="https://img.shields.io/pypi/v/wise_print.svg"></a>
</p>
`wise_print` is a lightweight Python package designed to enhance the debugging process in small scripts. It provides a customizable replacement for the built-in `print` function, allowing you to include additional contextual information in your output without the need for a full-fledged logging package.
## Overview
When debugging small scripts, you might not want to set up a logging configuration or deal with the overhead of logging frameworks. `wise_print` offers an easy way to add context to your print statements, making it easier to track the origin of messages and debug your code.
With `wise_print`, you can easily configure your output to include details such as:
- **Timestamp**: When the print statement was executed.
- **File Name**: The file in which the print statement was called.
- **Line Number**: The line number where the print statement was invoked.
## Installation
You can install `wise_print` using pip. Simply run:
```bash
pip install wise_print
```
## Usage
Here’s how you can use `wise_print` in your script:
1. **Import and Configure `wise_print`**:
```python
from wise_print import CustomPrinter
# Create an instance of CustomPrinter
printer = CustomPrinter(include_time=True, include_file=True, include_line=True, separator=' | ')
# Activate the custom print function
printer.activate()
```
2. **Use `print` as Usual**:
After activating `wise_print`, you can use the `print` function normally:
```python
print("This is a debug message")
```
The output will include the timestamp, filename, and line number based on your configuration.
3. **Deactivate `wise_print`**:
To return to the standard `print` behavior, simply deactivate `wise_print`:
```python
printer.deactivate()
print("This is a standard print message")
```
## Example
Here’s a complete example demonstrating the use of `wise_print`:
```python
from wise_print import CustomPrinter
# Create and configure the custom printer
printer = CustomPrinter(include_time=True, include_file=True, include_line=True, separator=':')
printer.activate()
# Example print statements
print("Starting process...")
for i in range(3):
print(f"Processing item {i}")
# Deactivate custom print
printer.deactivate()
print("Process finished.")
```
Output might look like:
```
2024-08-09T12:34:56:/path/to/your/script.py:8 | Starting process...
2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 0
2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 1
2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 2
Process finished.
```
## Comparison with Python's `logging` Package
`wise_print` and Python’s built-in `logging` package serve different purposes and have distinct advantages and limitations. Here’s a comparison to help you decide when to use each:
| Feature | `wise_print` | `logging` |
|-----------------------|---------------------------------------|----------------------------------------|
| **Ease of Use** | Simple and straightforward for small scripts. | Requires setup and configuration, but very flexible. |
| **Configuration** | Minimal configuration required. | Highly configurable with multiple handlers and formatters. |
| **Output** | Directly replaces `print` statements. | Supports multiple output destinations (console, files, remote servers). |
| **Performance** | Lightweight and fast. | Can be slower due to extensive features and configurations. |
| **Context Information** | Includes timestamp, filename, and line number. | Can include extensive context and metadata (log levels, exception info, etc.). |
| **Flexibility** | Limited to custom print behavior. | Highly flexible with log levels, formatting, and custom handlers. |
| **Use Case** | Best for quick debugging in small scripts. | Ideal for production code and complex applications requiring detailed logging. |
### When to Use `wise_print`
- **Quick Debugging**: When you need to quickly add context to print statements in small scripts or during early development stages.
- **Simplicity**: When you prefer a lightweight, straightforward solution without the complexity of logging configurations.
- **Minimal Setup**: When you want to avoid setting up a logging framework for small or one-off scripts.
### When to Use `logging`
- **Production Code**: For applications where detailed and configurable logging is required, including different log levels and multiple output destinations.
- **Complex Applications**: When you need advanced logging features such as logging to files, sending logs over the network, or integrating with external logging systems.
- **Structured Logging**: When you need structured and rich log information, including exceptions, context data, and custom log levels.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
## Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
Raw data
{
"_id": null,
"home_page": "https://github.com/dandpz/wise-print",
"name": "wise-print",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "print, pypi, package, logging",
"author": "Daniele Dapuzzo",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/b2/1e/a4d3eed13c142ebd869280813397be07262761fd327e187ec7b53bacc42e/wise_print-0.1.6.tar.gz",
"platform": null,
"description": "# Wise Print\n\n<p align=\"left\">\n <a href=\"https://pypi.python.org/pypi/wise_print\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/wise_print.svg\"></a>\n</p>\n\n`wise_print` is a lightweight Python package designed to enhance the debugging process in small scripts. It provides a customizable replacement for the built-in `print` function, allowing you to include additional contextual information in your output without the need for a full-fledged logging package.\n\n## Overview\n\nWhen debugging small scripts, you might not want to set up a logging configuration or deal with the overhead of logging frameworks. `wise_print` offers an easy way to add context to your print statements, making it easier to track the origin of messages and debug your code.\n\nWith `wise_print`, you can easily configure your output to include details such as:\n\n- **Timestamp**: When the print statement was executed.\n- **File Name**: The file in which the print statement was called.\n- **Line Number**: The line number where the print statement was invoked.\n\n## Installation\n\nYou can install `wise_print` using pip. Simply run:\n\n```bash\npip install wise_print\n```\n\n## Usage\n\nHere\u2019s how you can use `wise_print` in your script:\n\n1. **Import and Configure `wise_print`**:\n\n ```python\n from wise_print import CustomPrinter\n \n # Create an instance of CustomPrinter\n printer = CustomPrinter(include_time=True, include_file=True, include_line=True, separator=' | ')\n \n # Activate the custom print function\n printer.activate()\n ```\n\n2. **Use `print` as Usual**:\n\n After activating `wise_print`, you can use the `print` function normally:\n\n ```python\n print(\"This is a debug message\")\n ```\n\n The output will include the timestamp, filename, and line number based on your configuration.\n\n3. **Deactivate `wise_print`**:\n\n To return to the standard `print` behavior, simply deactivate `wise_print`:\n\n ```python\n printer.deactivate()\n print(\"This is a standard print message\")\n ```\n\n## Example\n\nHere\u2019s a complete example demonstrating the use of `wise_print`:\n\n```python\nfrom wise_print import CustomPrinter\n\n# Create and configure the custom printer\nprinter = CustomPrinter(include_time=True, include_file=True, include_line=True, separator=':')\nprinter.activate()\n\n# Example print statements\nprint(\"Starting process...\")\nfor i in range(3):\n print(f\"Processing item {i}\")\n\n# Deactivate custom print\nprinter.deactivate()\nprint(\"Process finished.\")\n```\n\nOutput might look like:\n\n```\n2024-08-09T12:34:56:/path/to/your/script.py:8 | Starting process...\n2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 0\n2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 1\n2024-08-09T12:34:56:/path/to/your/script.py:9 | Processing item 2\nProcess finished.\n```\n\n## Comparison with Python's `logging` Package\n\n`wise_print` and Python\u2019s built-in `logging` package serve different purposes and have distinct advantages and limitations. Here\u2019s a comparison to help you decide when to use each:\n\n| Feature | `wise_print` | `logging` |\n|-----------------------|---------------------------------------|----------------------------------------|\n| **Ease of Use** | Simple and straightforward for small scripts. | Requires setup and configuration, but very flexible. |\n| **Configuration** | Minimal configuration required. | Highly configurable with multiple handlers and formatters. |\n| **Output** | Directly replaces `print` statements. | Supports multiple output destinations (console, files, remote servers). |\n| **Performance** | Lightweight and fast. | Can be slower due to extensive features and configurations. |\n| **Context Information** | Includes timestamp, filename, and line number. | Can include extensive context and metadata (log levels, exception info, etc.). |\n| **Flexibility** | Limited to custom print behavior. | Highly flexible with log levels, formatting, and custom handlers. |\n| **Use Case** | Best for quick debugging in small scripts. | Ideal for production code and complex applications requiring detailed logging. |\n\n### When to Use `wise_print`\n\n- **Quick Debugging**: When you need to quickly add context to print statements in small scripts or during early development stages.\n- **Simplicity**: When you prefer a lightweight, straightforward solution without the complexity of logging configurations.\n- **Minimal Setup**: When you want to avoid setting up a logging framework for small or one-off scripts.\n\n### When to Use `logging`\n\n- **Production Code**: For applications where detailed and configurable logging is required, including different log levels and multiple output destinations.\n- **Complex Applications**: When you need advanced logging features such as logging to files, sending logs over the network, or integrating with external logging systems.\n- **Structured Logging**: When you need structured and rich log information, including exceptions, context data, and custom log levels.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Contributing\n\nContributions are welcome! Please fork the repository and submit a pull request with your changes.\n",
"bugtrack_url": null,
"license": null,
"summary": "Simple package to add info to print statements",
"version": "0.1.6",
"project_urls": {
"Bug Reports": "https://github.com/dandpz/wise-print/issues",
"Documentation": "https://github.com/dandpz/wise-print",
"Homepage": "https://github.com/dandpz/wise-print",
"Source Code": "https://github.com/dandpz/wise-print"
},
"split_keywords": [
"print",
" pypi",
" package",
" logging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1763329fb1393c0b26871d0e471db866b399ecf824ae2bfc92e01ff8249c4b75",
"md5": "bb8f0a293faefaeefa4f9ec62a50e78f",
"sha256": "11ddbe346365e8b246e1862243f2de80f40d66e10e0b0974d6a66b182ccf5ee8"
},
"downloads": -1,
"filename": "wise_print-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bb8f0a293faefaeefa4f9ec62a50e78f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5032,
"upload_time": "2024-08-11T14:31:42",
"upload_time_iso_8601": "2024-08-11T14:31:42.036116Z",
"url": "https://files.pythonhosted.org/packages/17/63/329fb1393c0b26871d0e471db866b399ecf824ae2bfc92e01ff8249c4b75/wise_print-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b21ea4d3eed13c142ebd869280813397be07262761fd327e187ec7b53bacc42e",
"md5": "a6420f027d04a1a99aab9fafdb4807ab",
"sha256": "9e52590e6f570a4f3d0aa00e22dc17ea141d84c893896bdba15b8d4b8b640fcf"
},
"downloads": -1,
"filename": "wise_print-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "a6420f027d04a1a99aab9fafdb4807ab",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 5809,
"upload_time": "2024-08-11T14:31:43",
"upload_time_iso_8601": "2024-08-11T14:31:43.474205Z",
"url": "https://files.pythonhosted.org/packages/b2/1e/a4d3eed13c142ebd869280813397be07262761fd327e187ec7b53bacc42e/wise_print-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-11 14:31:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dandpz",
"github_project": "wise-print",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "wise-print"
}