示例#1
0
def feed_queue(log_q):
    lines = open('www/access-log')
    lines = follow(lines)
    log = apache_log(lines)
    sendto_queue(log, log_q)
示例#2
0
import os
import time
from parser import apache_log


def follow(thefile, shutdown=None):
    thefile.seek(0, os.SEEK_END)
    try:
        while True:
            if shutdown and shutdown.is_set():
                break

            line = thefile.readline()
            if not line:
                time.sleep(0.1)
                continue
            yield line
    except GeneratorExit:
        print('Follow: Shutting down')


if __name__ == '__main__':
    logfile = open('www/access-log')
    loglines = follow(logfile)
    log = apache_log(loglines)
    r404 = (r for r in log if r['status'] == 404)

    for r in r404:
        print(r['host'], r['datetime'], r['request'])
示例#3
0
from genqueue import genfrom_queue, sendto_queue
from files import gen_cat
from tail import follow
from parser import apache_log


def multiplex(sources):
    in_q = queue.Queue()
    consumers = []
    for src in sources:
        thr = threading.Thread(target=sendto_queue, args=(src, in_q))
        thr.start()
        consumers.append(genfrom_queue(in_q))
    return gen_cat(consumers)


def print_r404(log):
    r404 = (r for r in log if r['status'] == 404)
    for r in r404:
        print(r['host'], r['datetime'], r['request'])


if __name__ == '__main__':
    lines = follow(open('www/access-log'))
    log = apache_log(lines)

    lines2 = follow(open('www/access-log'))
    log2 = apache_log(lines2)

    print_r404(multiplex([log, log2]))