https://github.com/mlabbe/execmode
Make Python logging, diagnostics and debug behavior depend on a debug/release execution flag.
https://github.com/mlabbe/execmode
Last synced: about 1 year ago
JSON representation
Make Python logging, diagnostics and debug behavior depend on a debug/release execution flag.
- Host: GitHub
- URL: https://github.com/mlabbe/execmode
- Owner: mlabbe
- License: mit
- Created: 2014-12-10T19:42:04.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-06T18:37:02.000Z (over 11 years ago)
- Last Synced: 2025-03-17T01:05:27.515Z (over 1 year ago)
- Language: Python
- Size: 152 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Execution Modes #
*Make Python logging, diagnostics and debug behavior depend on a debug/release execution flag.*
This is a Python 3 library.
C programmers are used to varying execution in debug mode. While Python offers `__debug__` and the `-O` flag, they are hardly used in practice.
## Usage ##
```python
import execmode.state
from execmode.logging import message, warning, error, fatal_error
#
execmode.state.set_state(execmode.state.DEBUG)
execmode.logging.set_color_diagnostics(True)
# all of these functions attach the calling stack frame to the message
message("use this instead of print for debug messaging.")
warning("same as message, but prefixes 'warning'")
error("attaches debugger if state is state.DEBUG and continues")
fatal_error("attaches debugger if state is state.DEBUG and exits with errorlevel")
```
## Color Diagnostics ##
`execmode.logging.set_color_diagnostics(True)` enables highlighting on warning and error messages in a standard console. Setting this does nothing unless the colorama module is installed.
pip install colorama
should do the trick.
## Changelog ##
### 1.1 ###
- optional color diagnostics added
- small bugfixes resulting from dogfooding
- dump() improved formatting