#43769 - 2003-08-07 11:45 AM
Re: Skip parts of code when in debug
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Basically, DIY. Here's what I do:
- Create a global debug variable, use in debug statement.
- Create a global log level variable, only log messages which comply.
The point of the log level is that it allows me to increase the amount of messages output when developing or debugging and reduce when in production without changing the code. Using a global debug means that sections of code can be conditionally executed.
code:
Global $gDEBUG $gDEBUG="ON" Global $gLOGLEVEL $gLOGLEVEL=9 ; 9=Verbose debug messages, 0=Normal
DEBUG $gDEBUG
The logging routine looks like this:
code:
Function Log($iLevel,$sMessage) If $iLevel <= $gLOGLEVEL @TIME+" "+$sMessage EndIf EndFunction
Say you have the following spread throughout your code:
code:
If $gDEBUG="ON" ; This code only executed when in debug. EndIf Log(0,"This is a fatal error message, always displayed"+@CRLF) Log(1,"Probaly some sort of informational message, like a startup/shutdown message"+@CRLF) Log(9,"A very verbose message - only displayed when detailed debugging is needed"+@CRLF)
Now, set $gDEBUG to "ON" or "OFF" depending on your mood. Set $gLOGLEVEL to the verbosity of messages you require.
These are cut down examples which you should expand as you need, for example in my scritps having debug on causes the log UDF to write all messages to a debug log file, while only displaying on screen those that meet the $gLOGLEVEL criteria.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2009 anonymous users online.
|
|
|