ASP 실행 오류 함수 코드 캡처 및 저장

4261 단어
프로세스 이름:catch(str)
사용 방법:
 
  
on error resume next
' ,
call catch(" ")

기능: IIS의 오류 알림 정보를 제거하고 사용자 정의 오류 알림을 사용자에게 되돌려주며 오류 정보를 txt 파일에 저장합니다. (물론 사용자 정의 페이지로 이동하는 것도 수정할 수 있습니다.)
코드:
 
  
option explicit
' ---------------------------
' on error resume next , ,
on error resume next
'i , , catch
i
call catch(" ")
'-------------------------------
' ---------------------------
function conn()
' on error resume next
on error resume next
'...........
call catch(" ")
end function
'-------------------------------
sub catch(str)
if err.number <> 0 then
dim tmp,path
' , "/error_log.txt"
path = "/table/error_log.txt"
tmp = tmp & " :" & geturl & vbcrlf
tmp = tmp & " :" & now() & vbcrlf
tmp = tmp & " IP:" & ip & vbcrlf
tmp = tmp & " :" & str & vbcrlf
tmp = tmp & " :" & err.number & vbcrlf
tmp = tmp & " :" & err.description & vbcrlf
tmp = tmp & " :" & err.source & vbcrlf & vbcrlf & vbcrlf
tmp = tmp & file_read(path)
call file_save(tmp,path,1)
err.clear()
die(str)
end if
end sub
' catch --------------------
sub echo(str)
response.write(str)
end sub
sub die(str)
echo(str) : response.end()
end sub
function ip()
ip = request.servervariables("remote_addr")
end function
' URL
function geturl()
dim tmp
if lcase(request.servervariables("https")) = "off" then
tmp = "http://"
else
tmp = "https://"
end if
tmp = tmp & request.servervariables("server_name")
if request.servervariables("server_port") <> 80 then
tmp = tmp & ":" & request.servervariables("server_port")
end if
tmp = tmp & request.servervariables("url")
if trim(request.querystring) <> "" then
tmp = tmp & "?" & trim(request.queryString)
end if
geturl = tmp
end function
' :
function file_read(path)
dim tmp : tmp = "false"
if not file_exists(path) then file_read = tmp : exit function
dim stream : set stream = server.CreateObject("ADODB.Stream")
with stream
.type = 2 '
.mode = 3 '
.charset = "gb2312"
.open
.loadfromfile(server.MapPath(path))
tmp = .readtext()
end with
stream.close : set stream = nothing
file_read = tmp
end function
' :
function file_save(str,path,model)
if model<>0 and model<>1 then model=1
if model=0 and file_exists(path) then file_save=true : exit function
dim stream : set stream = server.CreateObject("ADODB.Stream")
with stream
.type = 2 '
.charset = "gb2312"
.open
.writetext str
.savetofile(server.MapPath(path)),model+1
end with
stream.close : set stream = nothing
file_save = file_exists(path)
end function
' : /
function file_exists(path)
dim tmp : tmp = false
dim fso : set fso = server.CreateObject("Scripting.FilesyStemObject")
if fso.fileexists(server.MapPath(path)) then tmp = true
if fso.folderexists(server.MapPath(path)) then tmp = true
set fso = nothing
file_exists = tmp
end function
%>

좋은 웹페이지 즐겨찾기