Error.pbi error handler and logger include
Posted: Fri Apr 23, 2004 10:21 pm
i created at frist a simple thing and now i did a rewrite.
it displays the error message in a window, so you may have to close the screen if you want it to display an error.
for this release we have;
error icons
message logging with timestamps
internal error handling (i wasn't able to test this out very well so i can't tell if it works completely)
abort and continue buttons
display levels
logging levels
this can be used for debug purposes it has debug,info,warning error and logging levels on it
display level scale is 1=every thing from debug to fatal display 5=only fatal display
logging scale is the same way
to get it working properly use the following code with the nessary modifaction
so here the include
tell me how you think and what i need to fix :roll:
if you want to use teh error icons
create 32x32 bmps of fatal,error,warning,info,debug and place the bmps in the base of the source (or execute) directory
it displays the error message in a window, so you may have to close the screen if you want it to display an error.
for this release we have;
error icons
message logging with timestamps
internal error handling (i wasn't able to test this out very well so i can't tell if it works completely)
abort and continue buttons
display levels
logging levels
this can be used for debug purposes it has debug,info,warning error and logging levels on it
display level scale is 1=every thing from debug to fatal display 5=only fatal display
logging scale is the same way
to get it working properly use the following code with the nessary modifaction
Code: Select all
includefile "Error.pbi"
dlevel=5 ;display only Fatal errors
llevel=3; log warnings and errors
lfile="log.txt"
;message("fake error",5) ;show fatal
;message("fake debug",1) ;show debug
tell me how you think and what i need to fix :roll:
if you want to use teh error icons
create 32x32 bmps of fatal,error,warning,info,debug and place the bmps in the base of the source (or execute) directory
Code: Select all
;Error.pbi
;Created by: Dreglor
;on: 1-22-04
;last updated: 4-23-04
;requires:
;notes: use file id > 1. you need to set display level(dlevel.b),log level(llevel.b),log file(lfile.s)
;commands:
;Message_Logger(message.s,level)
;Message(string.s,level)
;handle_internal()
#Window_0=0
Enumeration
#img
#message
#continue
#endprog
#text
EndEnumeration
Global dlevel.b, llevel.b, lfile.s
Procedure message_logger(message.s,level)
;[hh:mm:ss mm/dd/yy] level str: message
If level=1 And llevel=5
OpenFile(1,lfile); i use 1 so there is no conflicts unless theres is the opening of muiltable files :/
FileSeek(Lof())
WriteStringN(FormatDate("[%hh:%mm:%ss %mm/%dd/%yy] ",Date())+"Debug : "+message)
CloseFile(1)
ProcedureReturn 1
ElseIf level=2 And llevel>=4
OpenFile(1,lfile)
FileSeek(Lof())
WriteStringN(FormatDate("[%hh:%mm:%ss %mm/%dd/%yy] ",Date())+"Info : "+message)
CloseFile(1)
ProcedureReturn 1
ElseIf level=3 And llevel>=3
OpenFile(1,lfile)
FileSeek(Lof())
WriteStringN(FormatDate("[%hh:%mm:%ss %mm/%dd/%yy] ",Date())+"Warning : "+message)
CloseFile(1)
ProcedureReturn 1
ElseIf level=4 And llevel>=2
OpenFile(1,lfile)
FileSeek(Lof())
WriteStringN(FormatDate("[%hh:%mm:%ss %mm/%dd/%yy] ",Date())+"Error : "+message)
CloseFile(1)
ProcedureReturn 1
ElseIf level=5 And llevel>=1
OpenFile(1,lfile)
FileSeek(Lof())
WriteStringN(FormatDate("[%hh:%mm:%ss %mm/%dd/%yy] ",Date())+"Fatal : "+message)
CloseFile(1)
ProcedureReturn 1
EndIf
EndProcedure
Procedure Message(string.s,level)
message_logger(string,level)
If level=1 And dlevel=5
message_logger(string,level)
If OpenWindow(#Window_0, 216, 0, 518, 211, #PB_Window_SystemMenu |#PB_Window_TitleBar | #PB_Window_ScreenCentered , "Debug Message")
If CreateGadgetList(WindowID())
ImageGadget(#img, 20, 20, 64, 64, LoadImage(0, "\debug.bmp"))
StringGadget(#message, 120, 20, 370, 80, "", #PB_String_ReadOnly)
ButtonGadget(#continue, 20, 160, 100, 30, "Continue Program")
ButtonGadget(#endprog, 380, 160, 100, 30, "Abort Program")
TextGadget(#text, 20, 110, 450, 40, "The message above is a debug message, debug messages may or may not mean theres an error it only to help when your game chrashes. If you wish to not see these messages please refer to the readme to turn it off.")
EndIf
EndIf
SetGadgetText(#message,string)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #continue
quit=1
ElseIf GadgetID = #endprog
quit=2
EndIf
EndIf
Until Event=#PB_EventCloseWindow Or quit=1 Or quit=2
If quit=2
End
EndIf
ElseIf level=2 And dlevel>=4
If OpenWindow(#Window_0, 216, 0, 518, 211, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Info Message")
If CreateGadgetList(WindowID())
ImageGadget(#img, 20, 20, 64, 64, LoadImage(0, "\info.bmp"))
StringGadget(#message, 120, 20, 370, 80, "", #PB_String_ReadOnly)
ButtonGadget(#continue, 20, 160, 100, 30, "Continue Program")
ButtonGadget(#endprog, 380, 160, 100, 30, "Abort Program")
TextGadget(#text, 20, 110, 450, 40, "The message above is a info message, info messages may or may not mean theres an error it only to help when your game chrashes. If you wish to not see these messages please refer to the readme to turn it off.")
EndIf
EndIf
SetGadgetText(#message,string)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #continue
quit=1
ElseIf GadgetID = #endprog
quit=2
EndIf
EndIf
Until Event=#PB_EventCloseWindow Or quit=1 Or quit=2
If quit=2
End
EndIf
ElseIf level=3 And dlevel>=3
If OpenWindow(#Window_0, 216, 0, 518, 211, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Warning Message")
If CreateGadgetList(WindowID())
ImageGadget(#img, 20, 20, 64, 64, LoadImage(0, "\warning.bmp"))
StringGadget(#message, 120, 20, 370, 80, "", #PB_String_ReadOnly)
ButtonGadget(#continue, 20, 160, 100, 30, "Continue Program")
ButtonGadget(#endprog, 380, 160, 100, 30, "Abort Program")
TextGadget(#text, 20, 110, 450, 40, "The message above is a warning message, warning messages means theres an error but the program can cooperate with it and there no need to abort. If you wish to not see these messages please refer to the readme to turn it off.")
EndIf
EndIf
SetGadgetText(#message,string)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #continue
quit=1
ElseIf GadgetID = #endprog
quit=2
EndIf
EndIf
Until Event=#PB_EventCloseWindow Or quit=1 Or quit=2
If quit=2
End
EndIf
ElseIf level=4 And dlevel>=2
If OpenWindow(#Window_0, 216, 0, 518, 211, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Error Message")
If CreateGadgetList(WindowID())
ImageGadget(#img, 20, 20, 64, 64, LoadImage(0, "\error.bmp"))
StringGadget(#message, 120, 20, 370, 80, "", #PB_String_ReadOnly)
ButtonGadget(#endprog, 380, 160, 100, 30, "Abort Program")
TextGadget(#text, 20, 110, 450, 40, "The message above is a error message,there may be a problem with corrupted files and/or bugs in the code, it may be fixed in an update. If you wish to not see these messages please refer to the readme to turn it off.")
EndIf
EndIf
SetGadgetText(#message,string)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
ElseIf GadgetID = #endprog
quit=2
EndIf
Until Event=#PB_EventCloseWindow Or quit=2
If quit=2
End
EndIf
ElseIf level=5 And dlevel>=1
If OpenWindow(#Window_0, 216, 0, 518, 211, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Fatal Message")
If CreateGadgetList(WindowID())
ImageGadget(#img, 20, 20, 64, 64, LoadImage(0, "\fatal.bmp"))
StringGadget(#message, 120, 20, 370, 80, "", #PB_String_ReadOnly)
ButtonGadget(#endprog, 380, 160, 100, 30, "Abort Program")
TextGadget(#text, 20, 110, 450, 40, "The message above is a fatal error message, this is a BIG error and it may be due to old/bad hardware or software that is required by the program this may not be able to be fixed by the author(s). If you wish to not see these messages please refer to the readme to turn it off.")
EndIf
EndIf
SetGadgetText(#message,string)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
ElseIf GadgetID = #endprog
quit=2
EndIf
Until Event=#PB_EventCloseWindow Or quit=2
If quit=2
End
EndIf
EndIf
EndProcedure
Procedure handle_internal()
message("An Internal Error has happend please inform the author of this: "+Str(GetErrorNumber())+" : "+GetErrorDescription(),5)
ClearError()
OnErrorResume()
EndProcedure
Procedure internal_error()
Repeat
OnErrorGosub(@handle_internal())
ForEver
EndProcedure
CreateThread(@internal_error(),0)