Skip to main content

Enhanced warning output using Rich with icons and colors.

Project description

xwarning

xwarning is a Python module that enhances the default warnings system using Rich, providing beautiful, color-coded warning messages with icons.

Features

  • Emoji-based warning indicators
  • Rich-colored terminal output
  • Drop-in replacement for warnings.warn()
  • Built-in support for common warning types:
    • DeprecationWarning
    • UserWarning
    • FutureWarning
    • RuntimeWarning
    • SyntaxWarning
    • ImportWarning
    • UnicodeWarning
    • Generic Warning
  • Optional file logging:
    • If log_file is a string, logs to the specified filename
    • If True, logs to system temp directory (Windows) or /var/log (Linux)
  • Fully configurable:
    • Toggle icons on/off
    • Toggle colors on/off

Installation

pip install xwarning

Usage

>> from xwarning import warn, configure

# Simple usage
>> warn("This is deprecated warning !", type="deprecated")

>> warn("This is user warning !", type="user")

>> warn("This is future warning !", type="future")

>> warn("This is runtime warning !", type="runtime")

>> warn("This is syntax warning !", type="syntax")

>> warn("This is import warning !", type="import")

>> warn("This is unicode warning !", type="unicode")

>> warn("This is general warning !", type="general")

>> configure(show_icon=False, show_color=True)

# Logging to file
>> log_path = "warnings.log"
>> configure(log_file=log_path)

>> warn(f"This will go to the log file! with log file name '{log_path}'", type="user")

>> log_path = True
>> configure(log_file=log_path)
>> warn(f"This will go to the log file! with log file name as bool in temp or /var/log directory", type="user")

# Extra instance
>> printer1 = WarningPrinter()
>> printer1.configure(show_icon=False, log_file=True)
>> printer1.warn("this user warning with printer1", type="user")

>> printer2 = WarningPrinter()
>> printer2.configure(show_icon=True, show_color=False)
>> printer2.warn("this runtime warning with printer2", type="runtime")

>> printer1.filterwarnings("ignore", category=UserWarning)

>> printer1.warn("This not will appear as a user warning with `filterwarning`", type="user")
>> printer1.warn("This will appear as a runtime warning without `filterwarning`", type="runtime")

Example Output

🛑 DEPRECATED: This is deprecated
⚠️ USER: This is a user warning!

Example Outputs

License

MIT License. See LICENSE for details.

author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xwarning-0.12.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xwarning-0.12-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file xwarning-0.12.tar.gz.

File metadata

  • Download URL: xwarning-0.12.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for xwarning-0.12.tar.gz
Algorithm Hash digest
SHA256 c84d562a7390bf68969fa3b29aa4a5d173cc2f51111890e35808035174f900a1
MD5 898a4e646427959ffa0e2354aee6011d
BLAKE2b-256 2f35a24994e162e42497042b48866f903355934a97c58247e068807b51510615

See more details on using hashes here.

File details

Details for the file xwarning-0.12-py3-none-any.whl.

File metadata

  • Download URL: xwarning-0.12-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for xwarning-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 fc82a750726fedd10e23fc200c4b5a3990f5e403dee51d738da14a0990b8cb29
MD5 ecd8fc7ee3f866fa84d81e5a00960d7c
BLAKE2b-256 2dc3ec6554dbee74e24099acb0b9aa794a43a90fce2a6951466e805da3ac4c7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page