Python-闭包函数例子

Python-闭包函数例子

2020-06-07 21:24:37发布 浏览数:466
概述:Python-闭包函数例子

�2

import logging

 

def log_header(logger_name):

    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(name)s] %(levelname)s %(message)s',

                        datefmt='%Y-%m-%d %H:%M:%S')

    logger = logging.getLogger(logger_name)

 

    def _logging(something, level):

        if level == 'debug':

            logger.debug(something)

        elif level == 'warning':

            logger.warning(something)

        elif level == 'error':

            logger.error(something)

        else:

            raise Exception("I dont know what you want to do?")

    return _logging

 

project_1_logging = log_header('project_1')

 

project_2_logging = log_header('project_2')

 

def project_1():

 

    project_1_logging('this is a debug info', 'debug')

    project_1_logging('this is a warning info', 'warning')

    project_1_logging('this is a error info', 'error')

 

def project_2():

 

    project_2_logging('this is a debug info', 'debug')

    project_2_logging('this is a debug info', 'warning')

    project_2_logging('this is a debug info', 'error')

 

project_1()

project_2()

源码来源:https://blog.csdn.net/sc_lilei/article/details/80464645

请先
登录
后评论
0 条评论
暂时没有评论
最新文章
更多