简体   繁体   中英

How to read debug info from IIS logs

I'm maintaining an old asp classic application. It uses Response.AppendToLog as its sole debug logging system. I only debug it on my localhost so the logging files are on my harddrive in the %SystemDrive%\inetpub\logs\LogFiles folder.

I'm looking for a tail-like program that shows these debug messages live. Maybe with a possibility to colour the messages based on a filter.

Update: I've started writing my own tail program in python using the info in Recipe 157035 . The logging lags behind by a minute approximately. Any ideas on improving it?

Why reinvent the wheel? You could use Snare for IIS (free) to log the information to Kiwi's Syslog Daemon (not free).

I finished it. Now all I have to do is Response.AppendToLog("#message"); where every space or weird character in message is replaced by an underscore. Too bad it lags behind by a minute or so, but it's better than nothing.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM