首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >经典asp中的异步日志记录

经典asp中的异步日志记录
EN

Stack Overflow用户
提问于 2011-05-04 10:05:21
回答 2查看 436关注 0票数 0

对于在IIS6.0中部署的经典asp应用程序,我需要将错误日志记录到一个文本文件中,以便日志记录将应用程序从日志资源中分离出来,从而允许应用程序在基础日志记录基础结构因任何原因而变得不可用时继续运行。对于类似类型的问题,我读到了其中一个回答,即可以使用xmlhttp。还有别的办法吗?请帮帮忙

EN

回答 2

Stack Overflow用户

发布于 2012-05-03 22:39:54

您希望记录哪些错误?

ASP错误?然后,您必须在每个站点上运行所有代码,并使用ON ERROR RESUME NEXT +编写一个错误处理程序。例如,您可以通过SSI includes在所有页面上包含这些内容。

因为经典的asp是单元线程化模型,所以你不能真的异步地做这件事!但是您可以编写COM+组件。这个组件有一个方法,你可以在其中传递err.number,description,source (+也许Request.ServerVariables("URL")) ByVal,然后快速返回。在组件内部,您可以启动一个异步线程来写入日志文件或将错误写入任何数据库。

我不确定这是否是你想要的,但如果是的话,那就是你可以做到的。

票数 0
EN

Stack Overflow用户

发布于 2020-06-18 19:24:29

这不完全是你想要的,但是这是一个用于Chrome的ASP经典日志记录解决方案,它提供了一个相当一致的使用javascript console.log()等的体验。日志记录将JS注入到响应中,并记录到开发人员控制台(F12)单元测试和示例用法中-内部警告:避免出现“脚本中的脚本”的情况

代码语言:javascript
复制
<%

' log from ASP lines to chrome dev console - using the same javascript syntax
' ref: https://developers.google.com/web/tools/chrome-devtools/console/api#dir

' to add this to your asp page:
' <!--#Include file ="log.asp"-->

' sample usage - see unit test at bottom

' to turn logging ON, you have those options:
'  console.active = true
'  run on localhost
'  add queryString log=1  (e.g. www.myweb.com?log=1)


class oConsole
    private isActive
    private oGroup
    private mGroupLabel
    private mGroupType
    Private Sub Class_Initialize(  )
        isActive = (Request.ServerVariables("SERVER_NAME") = "localhost") or _
                   (request.queryString("log") = "1") or _
                   session("log")
        set oGroup = nothing
    end sub

    Public Property Let active(a)
        isActive = a
        session("log") = cBool(a)
    End Property

    public property get active
      active = isActive
    end property

    private sub script(func, text)
        if not isActive then exit sub
        text = replace(text, """", "\""")
        if not oGroup is nothing then
            oGroup.add oGroup.count, func & "(""" & text & """)"
        else
            Response.Write "<script language=javascript>console." & func & "(""" & text & """)</script>" & vbCrLf
        end if
    end sub

    public sub log(Text)
        script "log", Text
    end sub

    public sub Warn(w)
        script "warn", w
    end sub

    public sub error(e)
        if e = "" then e = "Error 0x" & hex(err.number) & " " & err.description
        script "error", e
    end sub

    public sub assert(cond, message)
        if not cond then script "assert", """,""" & message
    end sub

    public sub logVar(Variable)
        log Variable & "=" & eval(Variable) 
    end sub

    public sub clear
        if not isActive then exit sub
        response.write "<script language=javascript>console.clear()</script>"  & vbCrLf
    end sub

    public sub group(label)
        set oGroup = CreateObject("Scripting.Dictionary")
        mGroupLabel = label
        mGroupType = "group"
    end sub

    public sub groupCollapsed(label)
        group label
        mGroupType = "groupCollapsed"
    end sub

    public sub groupEnd
        if isNull(oGroup) then exit sub
        Response.Write "<script language=javascript>" & vbCrLf
        response.write "console." & mGroupType & "(""" & mGroupLabel & """)" & vbCrLf
        dim X
        for each X in oGroup
            response.write "console." & oGroup.item(X) & vbCrLf 
        next
        response.write "console.groupEnd()" & vbCrLf
        response.write "</script>" & vbCrLf
        set oGroup = nothing
    end sub

end class

dim console
set console = new oConsole


sub logTest
    if not console.active then
      console.active = true
      console.clear 
      console.warn "logging activated for testing"
    else
        console.clear       
    end if
    console.log "hello "
    console.warn "warning"
    console.error "error"
    console.assert true, "should not see this"
    console.assert false, "Assertion"
    on error resume next
    f=1/0
    console.Error "" ' logs the Err object
    on error goto 0
    console.logVar "now"
    console.groupCollapsed "My collapsed group"
        console.log "L1"
        console.warn "W1"
        console.error "E1"
    console.groupEnd
    console.group "My group"
        console.log "L1"
        console.warn "W1"
        console.error "E1"
    console.groupEnd
    console.active = false
    console.error "can't see this"
    console.active = true
    console.log "should see that"
end sub


%>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5877701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档