FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'
logging.basicConfig(format=FORMAT)
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
debug('Protocol problem: %s', 'connection reset', extra=d)
Conditionally evaluated debug statements in Python