如何从IIS日志中读取调试信息

时间:2009-03-05 09:31:40

标签: debugging iis logging asp-classic

我正在维护一个旧的asp经典应用程序。 它使用Response.AppendToLog作为其唯一的调试日志系统。 我只在我的localhost上调试它,因此日志文件位于%SystemDrive%\ inetpub \ logs \ LogFiles文件夹中的硬盘上。

我正在寻找一个类似尾部的程序来实时显示这些调试消息。 也许有可能根据过滤器为消息着色。

更新:我已经开始使用Recipe 157035中的信息在python中编写自己的尾程序。伐木大约落后一分钟。关于改进它的任何想法?

2 个答案:

答案 0 :(得分:0)

为什么重新发明轮子?您可以使用Snare for IIS(免费)将信息记录到Kiwi's Syslog Daemon(非免费)。

答案 1 :(得分:0)

我说完了。现在,我所要做的只是Response.AppendToLog("#message");,其中消息中的每个空格或奇怪字符都被下划线替换。太糟糕了,它会落后一分钟左右,但它总比没有好。

import time, os, re

def tail_f(file):
    interval = 1.0

    while True:
        where = file.tell()
        line = file.readline()
        if not line:
            time.sleep(interval)
            file.seek(where)
        else:
            yield line

def run():
    #Set the filename and open the file
    filename = r"C:\inetpub\logs\LogFiles\W3SVC1\u_ex{0}.log".format(time.strftime("%y%m%d"))
    file = open(filename,'r')

    #Find the size of the file and move to the end
    st_results = os.stat(filename)
    st_size = st_results[6]
    file.seek(st_size)

    for line in tail_f(file):
        #ignore comments
        if line[0] != "#":
            line = line.strip()
            parts = line.split(" ")

            status = parts[10]
            if status == "304":
                continue

            when = parts[1]
            method = parts[3]
            path = parts[4]
            query = parts[5].split("|")[0].split("#")[0]

            if query == "-":
                query = ""
            elif query != "":
                query = "?"+query

            print when, method[0], status, path + query

            if status == "500":
                if parts[5].find("|") != -1:
                    errorparts = parts[5].replace("_", " ").split("|")[1:]
                    linenr = errorparts[0]
                    errornr = errorparts[1]
                    errormessage = errorparts[2]
                    print "Error {0} on line {1}\n{2}".format(errornr, linenr, errormessage)
            if parts[5].find("#") != -1:
                print "* "+("\n* ".join(parts[5].replace("_", " ").split("#")[1:]))

run()