jprinter - Your Ultimate Debugging Companion! ๐ฅ
Wassup, fam! ๐ Meet jprinter, your new go-to tool for debugging! ๐ฏ
This ain't just your regular print() function; we're talkin' next-level debugging that keeps it real and helps you crush those bugs! ๐ช
Table of Contents
What's jprinter All About? ๐ค
jprinter is here to replace that basic print() function and bring your debugging game into the future! ๐ We know that debugging can be a pain, so we've built this tool with all the features you need to make it real, fast, and efficient. ๐ค
Key Features That Keep It ๐ฏ
- Enhanced Output: See variable values, context (filename, line number, function name) all in one clean output.
- Customizable Prefixes: Set a custom prefix to make sure you know what's being printed from which part of your code! ๐ฃ๏ธ
- Built-in Context: Automatically adds the file name, line number, and function name, so you always know where the action is! ๐
- Colorized Output: Make your output stand out with custom colors that make it easier to read. ๐จ
sep and end: Full control over separators and end-of-line characters, just like the original print(). ๐ค
- Pretty Printing: Nicely format complex data structures like dictionaries and lists so they're easy to read. โจ
- File Logging: Log all your output to a file, with or without timestamps, for keeping track of everything. ๐
- Global Enable/Disable: Turn off all
jprinter output with a single command so you can clean up the console when needed. ๐ด
- Log Function: Output different log levels (debug, info, warning, error) for better organization and clarity! ๐๏ธ
How to Use jprinter Like a Pro
Basic Usage with jp and jprint
Here's a basic example of how to use jprint and its shortcut, jp:
from jprinter import jp, jprint
# Using jp for a quick print statement
jp("Hello, world!")
# Using jprint with multiple arguments
jprint("This is", "a", "test")
Logging with Different Levels
You can log with different levels using the log function:
from jprinter import log
log("This is a debug message", level="debug")
log("This is an info message", level="info")
log("This is a warning message", level="warning")
log("This is an error message", level="error")
Global Enable/Disable
You can disable and enable all jprinter output using the JPrintDebugger class:
from jprinter import jp
from jprinter.core import JPrintDebugger
jp("This will be printed")
JPrintDebugger.disable_all()
jp("This will not be printed")
JPrintDebugger.enable_all()
jp("This will be printed again")
Custom Prefixes
Set custom prefixes for different debugging sections:
from jprinter import jp
jp("Debug info here", prefix="DEBUG >>> ")
jp("Important note", prefix="NOTE >>> ")
Pretty Printing Complex Data Structures
Format complex data structures for readability:
from jprinter import jp
data = {"name": "HAI", "age": 17, "hobbies": ["coding", "gaming", "reading"]}
jp(data, pprint_options={"indent": 4})
Custom Separators
Use custom separators:
from jprinter import jp
jp("Keep", "it", "real", sep=" - ")
File Logging
Log your output to a file:
from jprinter import jp
jp("This is a log message", log_file="debug.log")
Installation - Keeping It Simple
Option 1: Copy and Paste (The Easiest Way)
Just drop the jprinter folder into your project's directory, and you're good to go! ๐ฏ No extra installations needed.
Option 2: Using pip (For the Pros)
If you like to keep it clean, install jprinter with pip:
pip install jprinter
Option 3: Installing to Python's Builtins (Advanced & Risky)
โ ๏ธ WARNING: Modifying Python's builtins can cause issues and is not recommended. Proceed with caution!
To use jprinter as a built-in function, edit builtins.py in your Python installation:
Locate builtins.py: Usually found in your Python installation directory.
Edit builtins.py: Add the following lines to the file:
from jprinter import jprint as print
Restart Python: This will make the changes effective.
Package Structure - Know Your Tools
Here's a breakdown of the key files:
__init__.py: Initializes the jprinter package.
builtins.py: Functions to integrate jprinter with Python builtins.
coloring.py: Handles the color magic.
core.py: The heart of jprinter with all the core functionality.
jp.py: The jp function for quick debugging.
jprint.py: The main module for jprint.
README.md: This file, for all the important documentation.
Output Format Examples - See It to Believe It
Basic jp Usage
from jprinter import jp
jp("Hello, world!")
Output:
JARVIS -> [test_jprint.py:2] in () >>> Hello, world!
Basic jprint Usage
from jprinter import jprint
jprint("Hello, world!")
Output:
JARVIS -> [test_jprint.py:2] in () >>> Hello, world!
Custom Prefix
from jprinter import jp
jp("Hello, world!", prefix="DEBUG >>> ")
Output:
DEBUG >>> [test_jprint.py:2] in () >>> Hello, world!
Pretty Print
from jprinter import jp
data = {"name": "HAI", "age": 17, "hobbies": ["coding", "gaming", "reading"]}
jp(data, pprint_options={"indent": 4})
Output:
JARVIS -> [test_jprint.py:2] in () >>> {
"name": "HAI",
"age": 17,
"hobbies": [
"coding",
"gaming",
"reading"
]
}
Logging Output
from jprinter import log
log("This is a warning", level="warning")
Output:
[WARNING] JARVIS -> [test_jprint.py:2] in () >>> This is a warning
Advanced Usage - Level Up Your Debugging Game
See how to use the global enable/disable and logging in the How to Use section.
Troubleshooting - When Things Get Tricky
Common Issues
ImportError: Make sure you have installed or copied the files properly.
- Output Not Working: Make sure the
JPrintDebugger is enabled and configured.
Let's Level Up Together!
Feel free to contribute to the project by submitting issues or pull requests. Let's make jprinter the best tool for all the devs out there! ๐ช
License - Keeping It Open and Free