Re:You say “cave dweller debugging”, I say debug logging
by bckr on Friday May 06, 2022 @01:59PM
(#31288074)
An idea that I've been kicking around is to, in Python codebases, have a @log decorator that first logs the name of the function, all of the parameters it's called with and a function call id, then the name of the function, its return value, and the same function call id. This can be applied to as many of the functions in the codebase as necessary to provide "replayability". Haven't got the chance to try it out yet.
[ Parent
| on HN ]
Re:You say “cave dweller debugging”, I say debug logging
by shakna on Friday May 06, 2022 @08:08PM
(#31290903)
import logging
import threading
logger = logging.getLogger(__name__)
def log(fn):
def log_inner(*a, **kw):
logger.info('%s(%s, %s) @ %s', fn, a, kw, threading.get_native_id())
return fn(*a, **kw)
return log_inner
It's pretty easy to grab all the arguments and thread, but grabbing the return would depend on you not mutating anything permanent, so that probably needs some special casing.