logutils.py 文件源码

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

项目:onefl-deduper 作者: ufbmi 项目源码 文件源码
def get_a_logger(name):
    """
    Read log config from `log.conf` if file is present.
    See the `log.conf.example` for a sample.

    :param name: string used for naming the logger
    """
    cwd = os.getcwd()
    log_conf = os.path.join(cwd, CONFIG_FILE)

    if os.path.exists(log_conf):
        logging.config.fileConfig(log_conf)
        log = logging.getLogger(name)
        figlet = get_figlet(name)

        if figlet:
            print(figlet.format(__version__))

        log.debug("{} logging was configured using: {}"
                  .format(name, log_conf))
        handlers = logging.getLoggerClass().root.handlers

        for h in [h for h in handlers if hasattr(h, 'baseFilename')]:
            log.debug("log file: {}".format(h.baseFilename))
    else:
        lformat = '%(asctime)s: %(name)s.%(levelname)s ' \
            '- %(filename)s+%(lineno)d: %(message)s'
        logging.basicConfig(format=lformat, level=logging.INFO)
        log = logging.getLogger(name)
        log.info("Logging was configured using defaults. "
                 " To change that please use {} .".format(CONFIG_FILE))

    return log
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号