I've built a small Python decorator called the Ephemeral Debugging Decorator. The goal is to make adding temporary debugging and timing to functions easier, without the usual cleanup.
Sometimes you need to log some values or time a function's execution to understand a bug. Often, this involves adding print statements or custom logging calls directly into the codebase. Once the bug is fixed, you have to remember to remove these lines, or comment them out. Forgetting to remove them can lead to unnecessary output in production or clutter in your version control history.
This decorator provides a cleaner approach. You can wrap any function with @ephemeral_debug. Then, you control whether the debug output appears by setting an environment variable: DEBUG_EPHEMERAL=true. If the variable is not set, or set to anything else, the decorator does nothing. This allows you to toggle the debugging behavior globally without modifying your code.
It's useful for quick inspections during development or for intermittent issues that are hard to reproduce. You can add the debug statements, run your application with the environment variable set, gather the information, and then turn it off just as easily.
Find it here:
Ephemeral Debugging Decorator
Top comments (0)