A utility for safely printing with optional color formatting and logging to file.
Project description
Safe Print Logging Utility
Table of Contents
Overview
The Safe Print Logging Utility is a Python script providing enhanced printing functionality with colorful formatting, logging capability, and handling of UTF-8 encoding issues across various data types.
The utility defines three main functions:
safe_print: Augments print functionality.error_info: Logs detailed error information.replace_invalid_utf8_characters: Mitigates issues with invalid UTF-8 characters.
Installation
Requirements
- Python 3.x
coloramapackage
Installation Steps
- Ensure Python is installed on your machine.
- Install the
coloramapackage using pip:pip install colorama
- Integrate the script into your project.
Installing with pip
Since the package is available on PyPI, you can install it using pip with the following command:
pip install safe_print_utils
Usage
1. safe_print
Description
Prints data with colorful formatting and logging options.
Parameters
data: Data to print, formatted/indented for dicts and lists.child_process_label: (Optional) Label identifying a child process.label_color: Color forchild_process_label(Default: "RED").prefix: (Optional) Custom output prefix.prefix_color: Prefix color (Default: "GREEN").text_color: (Optional) Main text color.highlight: Flag to highlight text with yellow background and black text (Default: False).secondary_highlight: Flag to highlight text with black background and yellow text (Default: False).file_path: (Optional) File path for logging (Default: "").file_lines_limit: Max lines in log file, older lines are removed (Default: 10000).show_time: Flag to prefix output with the time (Default: True).error: Flag to make text color red (Default: False).
Example
safe_print("Hello, World!", prefix="Info", prefix_color="GREEN")
2. error_info
Description
Prints and optionally logs detailed error information, including line number and traceback.
Parameters
error: Caught exception object.file_path: (Optional) Log file path (Default: "").file_lines_limit: Max lines in log file, older lines are removed (Default: 10000).
Example
try:
1/0
except Exception as e:
error_info(e)
3. replace_invalid_utf8_characters
Description
Replaces invalid UTF-8 characters within various data types.
Parameters
input_data: Data containing potential non-UTF-8 encoded characters.replacement_character: Character replacing invalid UTF-8 characters (Default: ' ').
Example
cleaned_data = replace_invalid_utf8_characters("some_data_with_invalid_utf8")
Additional Usage Notes
- Ensure text/log file encoding compatibility with UTF-8.
- Ensure correct and writable file path/directory when logging with
safe_print.
Contributors
- SyntaxSurge (https://syntaxsurge.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safe_print_utils-0.1.0.tar.gz.
File metadata
- Download URL: safe_print_utils-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aedf3e3631fb07975e77a9c893608e301eb2ee13cbba77ebaadb22f43f9ddf6f
|
|
| MD5 |
12a0c343a9996f999edcde56743a6177
|
|
| BLAKE2b-256 |
2fc5fce4e8e4503bc66d839fed73955b5e3ae606733838962ab119d8d447f399
|
File details
Details for the file safe_print_utils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: safe_print_utils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28138198e84faf0440a0b7dacc773a6861e722040b0f300748d1ff438107b3d3
|
|
| MD5 |
565830eee2660c63396ba9ee41d22a12
|
|
| BLAKE2b-256 |
0a99b88c454450bb7ea79dd61f9ef731fc722bc2d78a02019c0890c66c0defe9
|