Awesome library! I wish I'd thought to google for this when writing dozens of DEBUG log messages with expensive string formatting, usually pprint. For example the following is incomplete, the expensive call to pprint.pformat may still happen for some logging configurations:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Processing large data shape:\n%s", pprint.pformat(data_dict))
This might make a good example to include in the docs to help potential users imagine why they might use this. Untested, but in this case the expensive call should never happen unless this logging record is actually going to be emitted:
logger.debug(
"Processing large data shape:\n%s",
lazy_string.LazyString(functools.partial(pprint.pformat, data_dict)),
)
Awesome library! I wish I'd thought to google for this when writing dozens of
DEBUGlog messages with expensive string formatting, usuallypprint. For example the following is incomplete, the expensive call topprint.pformatmay still happen for some logging configurations:This might make a good example to include in the docs to help potential users imagine why they might use this. Untested, but in this case the expensive call should never happen unless this logging record is actually going to be emitted: