簡體   English   中英

如何從 IIS 日志中讀取調試信息

[英]How to read debug info from IIS logs

我正在維護一個舊的 asp 經典應用程序。 它使用 Response.AppendToLog 作為其唯一的調試日志系統。 我只在我的本地主機上調試它,所以日志文件位於我的硬盤驅動器的 %SystemDrive%\inetpub\logs\LogFiles 文件夾中。

我正在尋找一個類似尾巴的程序,可以實時顯示這些調試消息。 也許有可能根據過濾器為消息着色。

更新:我已經開始使用配方157035 中的信息在 python 中編寫我自己的尾部程序。 記錄大約滯后一分鍾。 有什么改進的想法嗎?

為什么要重新發明輪子? 您可以使用Snare for IIS (免費)將信息記錄到Kiwi 的 Syslog Daemon (非免費)。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM