Skip to main content

Wise Print

PyPI

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:

pip install wise_print

Usage

Here’s how you can use wise_print in your script:

  1. Import and Configure wise_print:

    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:

    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:

    printer.deactivate()
    print("This is a standard print message")
    

Example

Here’s a complete example demonstrating the use of wise_print:

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 file for more details.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

Metadata

Release files for wise-print 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wise-print 0.1.6
File Size Uploaded
wise_print-0.1.6.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wise-print 0.1.6
File Interpreter ABI Platform
wise_print-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / wise_print-0.1.6.tar.gz

Download URL wise_print-0.1.6.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9e52590e6f570a4f3d0aa00e22dc17ea141d84c893896bdba15b8d4b8b640fcf
BLAKE2b-256 checksum
How to use checksums
b21ea4d3eed13c142ebd869280813397be07262761fd327e187ec7b53bacc42e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / wise_print-0.1.6-py3-none-any.whl

Download URL wise_print-0.1.6-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11ddbe346365e8b246e1862243f2de80f40d66e10e0b0974d6a66b182ccf5ee8
BLAKE2b-256 checksum
How to use checksums
1763329fb1393c0b26871d0e471db866b399ecf824ae2bfc92e01ff8249c4b75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page