Example #1
0
    def __load_log(self):
        """
        Load the log handler
        """

        global sirano_logger
        log = sirano_logger

        fmt = logging.Formatter('%(asctime)s:%(levelname)8s:%(name)s:%(message)s')

        if log is not None:
            self.log = log
        else:
            log = logging.getLogger("sirano")
            sirano_logger = log

            # Console handler
            handler_console = logging.StreamHandler()
            handler_console.setLevel(logging.INFO)
            handler_console.setFormatter(fmt)
            log.addHandler(handler_console)

        if self.phase == 1:
            phase = 'discovery'
        elif self.phase == 2:
            phase = 'generation'
        elif self.phase == 3:
            phase = 'anonymisation'
        elif self.phase == 4:
            phase = 'validation'
        else:
            phase = 'others'

        # All file handler
        path = self.project.logs + '/' + phase + '/'
        makedirs(path)
        path += time.strftime("%Y-%m-%d_%H-%M-%S_")

        handler_critical = logging.FileHandler(path + 'critical.log', mode="a", encoding="utf-8")
        handler_critical.setLevel(logging.CRITICAL)
        handler_critical.setFormatter(fmt)
        handler_error = logging.FileHandler(path + 'error.log', mode="a", encoding="utf-8")
        handler_error.setLevel(logging.ERROR)
        handler_error.setFormatter(fmt)
        handler_info = logging.FileHandler(path + 'info.log', mode="a", encoding="utf-8")
        handler_info.setLevel(logging.INFO)
        handler_info.setFormatter(fmt)
        handler_debug = logging.FileHandler(path + 'debug.log', mode="a", encoding="utf-8")
        handler_debug.setLevel(logging.DEBUG)
        handler_debug.setFormatter(fmt)

        for hdlr in log.handlers:  # remove all old handlers
            if hdlr.stream == sys.stderr:
                break
            hdlr.flush()
            hdlr.close()
            log.removeHandler(hdlr)

        log.addHandler(handler_critical)
        log.addHandler(handler_error)
        log.addHandler(handler_info)
        log.addHandler(handler_debug)

        log.setLevel(logging.DEBUG)
        self.log = log
Example #2
0
 def load(self):
     """Create all dirs if not exist"""
     makedirs(self.root)
     makedirs(self.data)
     makedirs(self.input)
     makedirs(self.logs)
     makedirs(self.output)
     makedirs(self.report)
     makedirs(self.trash)
     makedirs(self.validation)
     makedirs(self.archives)