Пример #1
0
    def wrapper(self, *args, **kw):
        # Set the task name in the logger
        from flexget import logger
        logger.set_task(self.name)
        if self.output:
            # Hook up our log and stdout to give back to the requester
            old_stdout, old_stderr = sys.stdout, sys.stderr
            sys.stdout, sys.stderr = Tee(self.output, sys.stdout), Tee(self.output, sys.stderr)
            # TODO: Use a filter to capture only the logging for this execution?
            streamhandler = logging.StreamHandler(self.output)
            streamhandler.setFormatter(FlexGetFormatter())
            logging.getLogger().addHandler(streamhandler)
        old_loglevel = logging.getLogger().getEffectiveLevel()
        new_loglevel = logging.getLevelName(self.options.loglevel.upper())
        if old_loglevel != new_loglevel:
            log.info('Setting loglevel to `%s` for this execution.' % self.options.loglevel)
            logging.getLogger().setLevel(new_loglevel)

        try:
            return func(self, *args, **kw)
        finally:
            logger.set_task('')
            if self.output:
                sys.stdout, sys.stderr = old_stdout, old_stderr
                logging.getLogger().removeHandler(streamhandler)
            if old_loglevel != new_loglevel:
                log.debug('Returning loglevel to `%s` after task execution.' % logging.getLevelName(old_loglevel))
                logging.getLogger().setLevel(old_loglevel)
Пример #2
0
    def wrapper(self, *args, **kw):
        # Set the task name in the logger
        from flexget import logger
        logger.set_task(self.name)
        if self.output:
            # Hook up our log and stdout to give back to the requester
            old_stdout, old_stderr = sys.stdout, sys.stderr
            sys.stdout, sys.stderr = Tee(self.output, sys.stdout), Tee(self.output, sys.stderr)
            # TODO: Use a filter to capture only the logging for this execution?
            streamhandler = logging.StreamHandler(self.output)
            streamhandler.setFormatter(FlexGetFormatter())
            logging.getLogger().addHandler(streamhandler)
        old_loglevel = logging.getLogger().getEffectiveLevel()
        new_loglevel = logging.getLevelName(self.options.loglevel.upper())
        if old_loglevel != new_loglevel:
            log.info('Setting loglevel to `%s` for this execution.' % self.options.loglevel)
            logging.getLogger().setLevel(new_loglevel)

        try:
            return func(self, *args, **kw)
        finally:
            logger.set_task('')
            if self.output:
                sys.stdout, sys.stderr = old_stdout, old_stderr
                logging.getLogger().removeHandler(streamhandler)
            if old_loglevel != new_loglevel:
                log.debug('Returning loglevel to `%s` after task execution.' % logging.getLevelName(old_loglevel))
                logging.getLogger().setLevel(old_loglevel)
Пример #3
0
 def wrapper(self, *args, **kw):
     # Set the task name in the logger
     from flexget import logger
     logger.set_task(self.name)
     try:
         return func(self, *args, **kw)
     finally:
         logger.set_task('')
Пример #4
0
 def wrapper(self, *args, **kw):
     # Set the task name in the logger
     from flexget import logger
     logger.set_task(self.name)
     try:
         return func(self, *args, **kw)
     finally:
         logger.set_task('')
Пример #5
0
    def wrapper(self, *args, **kw):
        # Set the task name in the logger
        from flexget import logger
        logger.set_task(self.name)
        old_loglevel = logging.getLogger().getEffectiveLevel()
        new_loglevel = logging.getLevelName(self.options.loglevel.upper())
        if old_loglevel != new_loglevel:
            log.info('Setting loglevel to `%s` for this execution.' % self.options.loglevel)
            logging.getLogger().setLevel(new_loglevel)

        try:
            if self.output:
                with capture_output(self.output):
                    return func(self, *args, **kw)
            else:
                return func(self, *args, **kw)
        finally:
            logger.set_task('')
            if old_loglevel != new_loglevel:
                log.debug('Returning loglevel to `%s` after task execution.' % logging.getLevelName(old_loglevel))
                logging.getLogger().setLevel(old_loglevel)