https://github.com/thombashi/msgfy
msgfy is a Python library for convert Exception instance to a human-readable error message.
https://github.com/thombashi/msgfy
logging python-library
Last synced: about 1 month ago
JSON representation
msgfy is a Python library for convert Exception instance to a human-readable error message.
- Host: GitHub
- URL: https://github.com/thombashi/msgfy
- Owner: thombashi
- License: mit
- Created: 2018-04-22T08:28:22.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-17T06:35:31.000Z (over 1 year ago)
- Last Synced: 2025-04-27T07:36:04.954Z (about 2 months ago)
- Topics: logging, python-library
- Language: Python
- Homepage: https://pypi.org/project/msgfy/
- Size: 87.9 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. contents:: **msgfy**
:backlinks: top
:depth: 2Summary
====================================
msgfy is a Python library for convert Exception instance to a human-readable error message... image:: https://badge.fury.io/py/msgfy.svg
:target: https://badge.fury.io/py/msgfy
:alt: PyPI package version.. image:: https://img.shields.io/pypi/pyversions/msgfy.svg
:target: https://pypi.org/project/msgfy
:alt: Supported Python versions.. image:: https://github.com/thombashi/msgfy/actions/workflows/ci.yml/badge.svg
:target: https://github.com/thombashi/msgfy/actions/workflows/ci.yml
:alt: CI status of Linux/macOS/Windows.. image:: https://coveralls.io/repos/github/thombashi/msgfy/badge.svg?branch=master
:target: https://coveralls.io/github/thombashi/msgfy?branch=master
:alt: Test coverage.. image:: https://github.com/thombashi/msgfy/actions/workflows/github-code-scanning/codeql/badge.svg
:target: https://github.com/thombashi/msgfy/actions/workflows/github-code-scanning/codeql
:alt: CodeQLUsage
====================================Convert from Exception instance to an error message
------------------------------------------------------------------------
:Sample Code:
.. code:: pythonimport msgfy
def error_message_example():
try:
raise ValueError("example message")
except ValueError as e:
print(msgfy.to_error_message(e))error_message_example()
:Output:
::ValueError: example error message
Specify message format
------------------------------------
:Sample Code:
.. code:: pythonimport msgfy
def error_message_format_example():
try:
raise ValueError("example error message")
except ValueError as e:
print(msgfy.to_error_message(e, "{exception} {func_name}: {error_msg}"))error_message_format_example()
:Output:
::ValueError error_message_format_example: example error message
Convert from Exception instance to a debug message
------------------------------------------------------------------------
:Sample Code:
.. code:: pythonimport msgfy
def debug_message_example():
try:
raise ValueError("example debug message")
except ValueError as e:
print(msgfy.to_debug_message(e))debug_message_example()
:Output:
::ValueError (5) debug_message_example: example debug message
Available keywords for message formats
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+---------------------+-----------------------------------------------+
| Keyword | Replaced to |
+=====================+===============================================+
| ``"{exception}"`` | Exception class name |
+---------------------+-----------------------------------------------+
| ``"{file_name}"`` | File name that exception raised |
+---------------------+-----------------------------------------------+
| ``"{line_no}"`` | Line number where the exception raised |
+---------------------+-----------------------------------------------+
| ``"{func_name}"`` | Function name that exception raised |
+---------------------+-----------------------------------------------+
| ``"{error_msg}"`` | Message that passed to the exception instance |
+---------------------+-----------------------------------------------+Installation
====================================Install from PyPI
------------------------------
::pip install msgfy
Install from PPA (for Ubuntu)
------------------------------
::sudo add-apt-repository ppa:thombashi/ppa
sudo apt update
sudo apt install python3-msgfyDependencies
====================================
Python 3.7+
No external dependencies.Test dependencies
-----------------
- `pytest `__
- `tox `__