logging.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:combine 作者: llllllllll 项目源码 文件源码
def log_duration(operation, level='info', log=None):
    """Log the duration of some process.

    Parameters
    ----------
    operation : str
        What is being timed?
    level : str, optional
        The level to log the start and end messages at.
    log : Logger, optional
        The logger object to write to. By default this is the logger for the
        calling frame.
    """
    log = _get_logger_for_contextmanager(log)

    log.log(level.upper(), operation)
    start = datetime.now()
    try:
        yield
    finally:
        now = datetime.now()
        log.log(
            level.upper(),
            'completed {} (completed in {})',
            operation,
            naturaldelta(now - start),
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号