本文整理匯總了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)