How to log two variables values in a single logging in Python?
How to log two variables values in a single logging in Python?
The python logging functions support a built-in string replacement documented here. This logging supports both arg and kwarg replacement.
from sys import stderr
from logging import getLogger, StreamHandler, Formatter, DEBUG
l = getLogger()
sh = StreamHandler(stderr)
sh.setLevel(DEBUG)
f = Formatter(%(asctime)s - %(name)s - %(levelname)s - %(message)s)
sh.setFormatter(f)
l.addHandler(sh)
l.setLevel(DEBUG)
L0 = [abc, def, ghi]
L1 = [jkl, mno, pqr]
l.info(%(list_0)s - %(list_1)s, { list_0: L0, list_1 : L1 })
# identical to
l.info(%s - %s, L0, L1)
# identical to
l.info(%s - %s % (L0, L1))