Python celery.utils.log.get_logger() Examples

The following are 1 code examples of celery.utils.log.get_logger(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module celery.utils.log , or try the search function .
Example #1
Source File: app_vars.py    From lexpredict-contraxsuite with GNU Affero General Public License v3.0 4 votes vote down vote up
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)