Example #1
0
def worker(event_queue, runflag):
    ep = event_parser()
    while runflag.value:
        # blocking here if there is none event
        item = event_queue.get()
        try:
            le = ep.get_my_listen_event()
            etype = get_event_type(item)
            if le.exist(item, etype):
                print "catch the msg", item
            # my_log.info("queue recv msg: %s" % item)
        finally:
            time.sleep(0.05)
    else:
        my_log.error("worker exit")
Example #2
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 #3
0
def log_file_tail(filename, equeue, switch):
    tailf = subprocess.Popen(['tail', '-F', filename],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
    sp = select.poll()
    fd = sp.register(tailf.stdout)
    while True:
        if sp.poll(1):
            if not switch.value:
                sp.unregister(tailf.stdout)
                tailf.kill()
                break
            line = tailf.stdout.readline()
            event = log_to_event(line, filename)
            if event != None:
                try:
                    equeue.put(event)
                    # my_log.info("queue put msg: %s" % event)
                except Exception:
                    my_log.error("event can't put into equeue %s" % event)
        else:
            sleep(0.05)