I would like the logger to print the linenumber where the subprocess.run method is called, the example below prints the linenumber where the wrapfunction is defined
#!/usr/bin/env python3
import logging, sys, functools, subprocess
logging.basicConfig(stream=sys.stdout, level=logging.INFO,style='{',format='⬬ {lineno:4d} ⬤ {pathname} ⬮\n{msg}')
def wrap_function(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
logging.info((args,kwargs)) # lineno=9
return func(*args ,**kwargs)
return wrapper
subprocess.run = wrap_function(subprocess.run)
subprocess.run('ls',timeout=10,shell=True) # lineno=15
Of course I get the line number where logging.info is called:
# current output:
#⬬ 9 ⬤ ./PycharmProjects/02.py ⬮
#(('ls',), {'timeout': 10, 'shell': True})
Is there a way to define the msg argument to logging.info without calling logging.info? This is the output I would like to have:
# output I would like to have:
#⬬ 15 ⬤ ./PycharmProjects/02.py ⬮
#(('ls',), {'timeout': 10, 'shell': True})