【问题标题】:How to read debug info from IIS logs如何从 IIS 日志中读取调试信息
【发布时间】:2010-10-11 11:24:52
【问题描述】:

我正在维护一个旧的 asp 经典应用程序。 它使用 Response.AppendToLog 作为其唯一的调试日志系统。 我只在我的本地主机上调试它,所以日志文件在我的硬盘驱动器的 %SystemDrive%\inetpub\logs\LogFiles 文件夹中。

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

更新:我已经开始使用Recipe 157035 中的信息在 python 中编写我自己的尾部程序。记录大约滞后一分钟。有什么改进的想法吗?

【问题讨论】:

    标签: debugging iis logging asp-classic


    【解决方案1】:

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

    【讨论】:

    • 我已经尝试过 snare 和 epilog,但似乎都不像我想要的那样容易使用。我似乎无法让他们向我展示我的日志。
    【解决方案2】:

    我写完了。现在我要做的就是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()
    

    【讨论】:

      猜你喜欢
      • 2017-01-23
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2019-06-05
      • 1970-01-01
      • 2016-03-19
      相关资源
      最近更新 更多