Example #1
0
def log_to_event(line, filename):
    program, fobj = get_log_properties(filename)
    split_str = map(str.strip, line.split(fobj["separator"]))
    field_nums = len(fobj["format"])
    parse_nums = len(split_str)
    log_dict = {}
    if parse_nums >= field_nums:
        split_str[field_nums - 1] = ' '.join(split_str[field_nums - 1:])
        for i in range(0, field_nums):
            field_name = fobj["format"][i]
            log_dict[field_name] = split_str[i].lower()
        tmp_log = log_event(location=filename, program=program, exec_mod="",
                            time=log_dict["time"],level=log_dict["level"],
                            info=log_dict["info"])
        return tmp_log
    else:
        my_log.error("line error in log %s" % line)
        return None
Example #2
0
 def log_event_parse(self, p_dict):
     try:
         location = p_dict.get("location")
         program = p_dict.get("program")
         level = p_dict.get("level")
         info = p_dict.get("info")
         timediff = p_dict.get("timediff")
         exec_mod = p_dict.get("exec")
         t_event = log_event(location=location, program=program, exec_mod = exec_mod,
                             time=timediff, level=level, info=info)
         if t_event:
             self.listen_logfile.append(location);
             self.todo.append({"event":t_event,"etype":0})
             return True
         else:
             return False
     except Exception, e:
         return False