当前位置: 首页>>代码示例>>Python>>正文


Python log.get_logger方法代码示例

本文整理汇总了Python中celery.utils.log.get_logger方法的典型用法代码示例。如果您正苦于以下问题:Python log.get_logger方法的具体用法?Python log.get_logger怎么用?Python log.get_logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在celery.utils.log的用法示例。


在下文中一共展示了log.get_logger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reset_loggers_level

# 需要导入模块: from celery.utils import log [as 别名]
# 或者: from celery.utils.log import get_logger [as 别名]
def reset_loggers_level():
    """
    Reset loggers' level from AppVar
    """

    def getEffectiveLevel(self):
        """
        Get the effective level for this logger.

        Loop through this logger and its parents in the logger hierarchy,
        looking for a non-zero logging level. Return the first one found.
        """
        logger = self

        # custom logic
        # cannot use AppVar due to circular import issue
        app_var_level = redis.pop(f'app_var:Logging:logger:{logger.name}:log_level')
        if app_var_level:
            app_var_level = app_var_level.upper()
            if app_var_level in logging._levelToName.values():
                logger.setLevel(app_var_level)

                # log sql to console
                if logger.name == 'django.db.backends':
                    handler = logging.StreamHandler()
                    handler.setLevel(logger.level)
                    logger_handler_classes = [i.__class__ for i in logger.handlers]
                    if redis.pop(f'app_var:Logging:logger:{logger.name}:log_to_console') is True:
                        if handler.__class__ not in logger_handler_classes:
                            logger.addHandler(handler)
                    else:
                        logger.handlers = [i for i in logger.handlers if i.__class__ != handler.__class__]
        # end custom logic

        while logger:
            if logger.level:
                return logger.level
            logger = logger.parent
        return logging.NOTSET

    # reset Project loggers
    for logger_name in settings.LOGGING['loggers']:
        logger = logging.getLogger(logger_name)
        logger.getEffectiveLevel = types.MethodType(getEffectiveLevel, logger)

    # reset celery loggers
    for logger_name in celery_logger_names:
        logger = get_logger(logger_name)
        logger.getEffectiveLevel = types.MethodType(getEffectiveLevel, logger) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:51,代码来源:app_vars.py


注:本文中的celery.utils.log.get_logger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。