Python: how to do lazy debug logging

后端 未结 3 781
无人共我
无人共我 2020-12-16 21:30

I have some python like this:

def foo():
    logger = logging.getLogger()
    # do something here
    logger.debug(\'blah blah {}\'.format(expensive_func()))         


        
3条回答
  •  旧时难觅i
    2020-12-16 22:06

    You can use stringlike library to add laziness to your messages

    E.g.:

    logger.debug(
        'blah blah {value}'
        .format(
            value=LazyString(expensive_func)
        )
    )
    

    Lib link: https://github.com/CovenantEyes/py_stringlike

提交回复
热议问题