Beispiel #1
0
    def log_message(cls, level, msg, ctx):
        """
        \brief Logs an message
        \param level (string) Log level
        \param msg (string / list of strings) Message string, or List of message strings
        \param ctx (dict) Context for the message strings
        """
        caller = None

        if not Options().log_duplicates:
            try:
                count = cls.seen.get(msg, 0)
                cls.seen[msg] = count + 1
            except TypeError as e:
                # Unhashable types in msg
                count = 0

            if count == 1:
                msg += (
                    " -- REPEATED -- Future similar messages will be silently ignored. Please use the --log_duplicates option to allow for duplicates",
                )
            elif count > 1:
                return

        if level == 'DEBUG':
            caller = caller_name(skip=3)
            # Eventually remove "" added to the configuration file
            try:
                paths = tuple(
                    s.strip(' \t\n\r') for s in Options().debug.split(','))
            except:
                paths = None
            if not paths or not caller.startswith(paths):
                return

        logger = Log().get_logger()
        msg_str = cls.build_message_string(msg, ctx)

        if logger:
            logger_fct = getattr(logger, level.lower())
            logger_fct("%s(): %s" % (inspect.stack()[2][3], msg_str))
        else:
            cls.print_msg(msg_str, level, caller)
Beispiel #2
0
 def tmp(cls, *msg):
     cls.print_msg(' '.join(map(lambda x: "%r" % (x, ), make_list(msg))),
                   'TMP', caller_name())
Beispiel #3
0
 def tmp(cls, *msg):
     cls.print_msg(' '.join(map(lambda x: "%r"%x, make_list(msg))), 'TMP', caller_name())
Beispiel #4
0
        if not Options().log_duplicates:
            try:
                count = cls.seen.get(msg, 0)
                cls.seen[msg] = count + 1
            except TypeError, e:
                # Unhashable types in msg
                count = 0
            
            if count == 1:
                msg += (" -- REPEATED -- Future similar messages will be silently ignored. Please use the --log_duplicates option to allow for duplicates",)
            elif count > 1:
                return
            
        if level == 'DEBUG':
            caller = caller_name(skip=3)
            # Eventually remove "" added to the configuration file
            try:
                paths = tuple(s.strip(' \t\n\r') for s in Options().debug.split(','))
            except:
                paths = None
            if not paths or not caller.startswith(paths):
                return

        logger = Log().get_logger()
        msg_str = cls.build_message_string(msg, ctx)
            
        if logger:
            logger_fct = getattr(logger, level.lower())
            logger_fct("%s(): %s" % (inspect.stack()[2][3], msg_str))
        else: