Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrintEvents

PrintEvents is a Python utility class built on top of the rich library to provide standardized, color-coded logging and display capabilities across an application. It allows developers to use predefined "tags" (e.g., db, error, success) to ensure consistent visual output in terminal interfaces.

Features

  • Styled Logging: Easily log messages with specific semantic tags that map to a custom color theme.
  • Customizable Theme: A centralized theme defines how each tag is rendered.
  • Error Reporting: Detailed exception information (file, function, line number) can be formatted and displayed with specialized error styling.
  • CLI Utilities: Includes helper methods for capturing styled text for use in command-line interfaces.

Installation

Ensure you have the rich library installed:

pip install rich
or
uv add rich

Usage

Basic Logging

from nuPac.PrintEvents.main import PrintEvents

log = PrintEvents()

# Using predefined tags
log.display("db", "Connecting to database...")
log.display("success", "Data retrieved successfully!")
log.display("error", "An unexpected error occurred.")

Error Information

PrintEvents can format exception details for clear debugging:

try:
    1 / 0
except Exception as e:
    log = PrintEvents()
    log.error_info(e, custom_msg="Something went wrong with calculation")

CLI Prompt Simulation

Use the cli method to capture styled text for use in interactive prompts:

log = PrintEvents()
prompt = log.cli("Enter your name: ", "cyan")
print(f"Captured prompt: {prompt}")

API Reference

Method Description
display(tag, message) Logs a message with the style associated with the given tag.
error_info(e, custom_msg="") Formats an exception and displays it using the failure tag.
cli(tag, color) Captures a styled string of text for use in CLI outputs.
display_all() A utility method that iterates through all tags in the current theme and prints "test".

Dependencies

  • rich

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages