ASP's Debug class

Source: Internet
Author: User
Tags bool session id ole servervariables split

ASP in the most headaches is the debugging process is inconvenient, I think many friends will use such a method "Response.Write", and then output related statements to see whether the correct. A few days ago wrote a thousands of lines of the page, there are about seven or eight sub/function, debugging when the use of more than 30 Response.Write, days, debugging after the 30 deleted one after another, tired!

Today see an ASP in the Debug Class (VBS), a try, absolutely!

The use method is simple:

Test.asp

<!--#INCLUDE file= "debuggingconsole.asp"-->
<%
output= "XXXX"
Set debugstr = New debuggingconsole
Debugstr. Enabled = True
Debugstr. Print "parameter output value", Output
''......
Debugstr.draw
Set debugstr = Nothing
%>

===================================================

Debuggingconsole.asp

<%
Class Debuggingconsole

Private dbg_enabled
Private Dbg_show
Private Dbg_requesttime
Private Dbg_finishtime
Private Dbg_data
Private Dbg_db_data
Private Dbg_allvars
Private Dbg_show_default
Private Divsets (2)

' Construktor => set the default values
Private Sub Class_Initialize ()
Dbg_requesttime = Now ()
Dbg_allvars = False
Set dbg_data = Server.CreateObject ("Scripting.Dictionary")
Divsets (0) = "<tr><td style=" cursor:hand; ' onclick= ' Javascript:if ("document.getElementById sectname# '). style.display== ' None ') {document.getElementById (' data#sectname# '). style.display= ' block '; Else{document.getelementbyid (' data#sectname# '). style.display= ' None ';} "" ><div id=sect#sectname# style= "Font-weight:bold;cursor:hand;background: #7EA5D7; color:white;padding-left:4 ;p adding-right:4;padding-bottom:2; ""  >| #title #| <div id=data#sectname# style= "cursor:text;display:none;background: #FFFFFF;p adding-left:8;" "onclick=" " Window.event.cancelBubble = true; ""  >| #data #| </div>|</div>| "
Divsets (1) = "<tr><td><div id=sect#sectname# style=" "font-weight:bold;cursor:hand;background:# 7ea5d7;color:white;padding-left:4;padding-right:4;padding-bottom:2 "" "Onclick=" "Javascript:if ( document.getElementById (' data#sectname# '). style.display== ' None ') {document.getElementById (' data#sectname# ') '). style.display= ' block '; Else{document.getelementbyid (' data#sectname# '). style.display= ' None ';} ""  >| #title #| <div id=data#sectname# style= "cursor:text;display:block;background: #FFFFFF;p adding-left:8;" "onclick=" " Window.event.cancelBubble = true; ""  >| #data #| </div>|</div>| "
Divsets (2) = "<tr><td><div id=sect#sectname# style=" "Background: #7EA5D7; color:lightsteelblue; Padding-left:4;padding-right:4;padding-bottom:2; ""  >| #title #|  <div id=data#sectname# style= "Display:none;background:lightsteelblue;padding-left:8" ">| #data #| </div>|</div>| "
Dbg_show_default = "0,0,0,0,0,0,0,0,0,0,0"
End Sub

Public Property Let-Enabled (bnewvalue) ' [bool] Sets ' Enabled ' to true or false
dbg_enabled = Bnewvalue
End Property
Public Property Get Enabled ' [bool] Gets the ' enabled ' value
Enabled = dbg_enabled
End Property

Public Property Let Show (Bnewvalue) ' [string] Sets the debugging panel. Where each digit in the string represents a debug information pane in order (one of the them). 1=open, 0=closed
Dbg_show = Bnewvalue
End Property
Public Property Get Show ' [string] Gets the debugging panel.
Show = Dbg_show
End Property

Public Property Let Allvars (Bnewvalue) ' "[bool] Sets wheather All variables would be displayed or not. True/false
Dbg_allvars = Bnewvalue
End Property
Public Property Get Allvars ' "[bool] Gets If all variables would be displayed.
Allvars = Dbg_allvars
End Property

''************************************************************************************************************* *****
' @SDESCRIPTION: Adds A variable to the debug-informations.
' @PARAM:-label [string]: Description of the variable
' @PARAM:-Output [variable]: the variable itself
''************************************************************************************************************* *****
Public Sub Print (label, output)
If dbg_enabled Then
If Err.Number > 0 Then
Call Dbg_data.add Validlabel (label), "!!! Error: "& Err.Number &" "& Err. Description)
Err. Clear
Else
UniqueID = Validlabel (label)
Response.Write UniqueID
Call Dbg_data.add (UniqueID, Output)
End If
End If
End Sub

''************************************************************************************************************* *****
"* Validlabel
''************************************************************************************************************* *****
Private Function Validlabel (ByVal label)
Dim i, LbL
i = 0
LBL = Label
Todo
If not dbg_data.exists (LBL) then Exit Do
i = i + 1
LBL = label & "(& I &)"
Loop Until I = i

Validlabel = LBL
End Function

''************************************************************************************************************* *****
"* Printcookiesinfo
''************************************************************************************************************* *****
Private Sub Printcookiesinfo (ByVal divsetno)
Dim tbl, Cookie, key, TMP
For all cookies in Request.Cookies
If not Request.Cookies (cookie). HasKeys Then
TBL = AddRow (tbl, Cookie, request.cookies (cookie))
Else
For each key in Request.Cookies (cookie)
TBL = AddRow (tbl, Cookie & "(" & Key & "), Request.Cookies (cookie) (key)
Next
End If
Next

TBL = maketable (TBL)
If Request.Cookies.count <= 0 Then Divsetno = 2
TMP = replace (replace (Divsets (Divsetno), "#sectname #", "Cookies"), "#title #", "Cookies"), "#data #", TBL)
Response.Write Replace (tmp, "|", vbCrLf)
End Sub

''************************************************************************************************************* *****
"* Printsummaryinfo
''************************************************************************************************************* *****
Private Sub Printsummaryinfo (ByVal divsetno)
Dim tmp, TBL
TBL = AddRow (TBL, "Time of Request", Dbg_requesttime)
TBL = AddRow (TBL, "Elapsed Time", DateDiff ("s", Dbg_requesttime, Dbg_finishtime) & "seconds")
TBL = AddRow (TBL, Request Type, Request.ServerVariables ("Request_method"))
TBL = AddRow (TBL, Status Code, Response.Status)
TBL = AddRow (TBL, "Script Engine", ScriptEngine & "" & ScriptEngineMajorVersion & "." & Scriptengineminorv Ersion & "." & ScriptEngineBuildVersion)
TBL = maketable (TBL)
TMP = replace (replace (Divsets (Divsetno), "#sectname #", "SUMMARY"), "#title #", "SUMMARY INFO"), "#data #", TBL)
Response.Write Replace (tmp, "|", vbCrLf)
End Sub

''************************************************************************************************************* *****
' @SDESCRIPTION: Adds the Database-connection object to the debug-instance. To display Database-information
' @PARAM:-Osqldb [Object]: Connection-object
''************************************************************************************************************* *****
Public Sub Grabdatabaseinfo (ByVal osqldb)
Dbg_db_data = AddRow (Dbg_db_data, "ADO Ver", osqldb.version)
Dbg_db_data = AddRow (dbg_db_data, OLE DB Ver, Osqldb.properties ("OLE DB Version"))
Dbg_db_data = AddRow (Dbg_db_data, DBMS, Osqldb.properties ("DBMS Name") & "Ver:" & Osqldb.properties ("DBMS vers Ion "))
Dbg_db_data = AddRow (Dbg_db_data, "Provider", Osqldb.properties ("Provider Name") & "Ver:" & Osqldb.properties (" Provider Version "))
End Sub

''************************************************************************************************************* *****
"* Printdatabaseinfo
''************************************************************************************************************* *****
Private Sub Printdatabaseinfo (ByVal divsetno)
Dim tbl
TBL = maketable (dbg_db_data)
TBL = replace (replace (Divsets (Divsetno), "#sectname #", "Database"), "#title #", "Database INFO"), "#data #", TBL)
Response.Write Replace (TBL, "|", vbCrLf)
End Sub

''************************************************************************************************************* *****
"* printcollection
''************************************************************************************************************* *****
Private Sub printcollection (Byval Name, Byval Collection, Byval Divsetno, Byval ExtraInfo)
Dim Vitem, TBL, Temp
For each vitem in Collection
If IsObject (Collection (Vitem)) and name <> "SERVER VARIABLES" and name <> "QueryString" and name <> "for M "Then
TBL = AddRow (TBL, Vitem, "{object}")
ElseIf IsNull (Collection (vitem)) Then
TBL = AddRow (TBL, Vitem, "{null}")
ElseIf IsArray (Collection (vitem)) Then
TBL = AddRow (TBL, Vitem, "{array}")
Else
If Dbg_allvars Then
TBL = AddRow (TBL, "<nobr>" & Vitem & "</nobr>", server. HTMLEncode (Collection (Vitem))
ElseIf (Name = "SERVER VARIABLES" and Vitem <> "All_http" and Vitem <> "All_raw") or Name <> "Server VAR" Iables "Then
If Collection (vitem) <> "" Then
TBL = AddRow (TBL, Vitem, server. HTMLEncode (Collection (Vitem))) ' & ' {& TypeName (Collection (Vitem)) & "}"
Else
TBL = AddRow (TBL, Vitem, "...")
End If
End If
End If
Next
If ExtraInfo <> "" Then tbl = tbl & "<tr><td colspan=2>TBL = maketable (TBL)
If Collection.count <= 0 then Divsetno =2
TBL = replace (replace (Divsets (Divsetno), "#title #", Name), "#data #", TBL)
TBL = replace (TBL, "#sectname #", replace (Name, "", ""))
Response.Write Replace (TBL, "|", vbCrLf)
End Sub

''************************************************************************************************************* *****
"* AddRow
''************************************************************************************************************* *****
Private Function AddRow (ByVal T, ByVal Var, ByVal Val)
t = t & "|<tr valign=top>|<td>|" & var & "|<td>=" & Val & "|</tr>"
AddRow = t
End Function

''************************************************************************************************************* *****
"* maketable
''************************************************************************************************************* *****
Private Function Maketable (ByVal tdata)
Tdata = "|<table border=0 style=" "Font-size:10pt;font-weight:normal;" > "+ tdata +" </table>| "
Maketable = Tdata
End Function

''************************************************************************************************************* *****
"' @SDESCRIPTION: Draws the Debug-panel
''************************************************************************************************************* *****
Public Sub Draw ()
If dbg_enabled Then
Dbg_finishtime = Now ()

Dim Divset, X
Divset = Split (Dbg_show_default, ",")
Dbg_show = Split (Dbg_show, ",")

For x = 0 To UBound (dbg_show)
Divset (x) = Dbg_show (x)
Next

Response.Write "<br><table width=100% cellspacing=0 border=0 style=" "FONT-FAMILY:ARIAL;FONT-SIZE:9PT; Font-weight:normal; "" ><tr><td><div style= "" Background: #005A9E; Color:white;padding:4;font-size:12pt;font-weight: bold; "" >Debugging-console:</DIV> "
Call Printsummaryinfo (Divset (0))
Call Printcollection ("VARIABLES", Dbg_data,divset (1), "")
Call Printcollection ("QueryString", Request.QueryString (), Divset (2), "")
Call Printcollection ("FORM", Request.Form (), Divset (3), "")
Call Printcookiesinfo (Divset (4))
Call Printcollection ("session", Session.Contents (), Divset (5), AddRow (AddRow (AddRow ("", "Locale ID", Session.LCID & "(&h & Hex (session.lcid) &)"), "Code Page", Session.CodePage), "Session ID", Session.SessionID)
Call Printcollection ("Application", Application.Contents (), Divset (6), "")
Call Printcollection ("SERVER VARIABLES", Request.ServerVariables (), Divset (7), AddRow ("", "Timeout", Server.ScriptTimeout))
Call Printdatabaseinfo (Divset (8))
Call Printcollection ("Session STATIC OBJECTS", Session.StaticObjects (), Divset (9), "")
Call Printcollection ("Application STATIC OBJECTS", Application.staticobjects (), Divset (10), "")
Response.Write "</Table>"
End If
End Sub

"' destructor
Private Sub Class_Terminate ()
Set Dbg_data = Nothing
End Sub

End Class

%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.