Save yourself some time

I see a lot of times people write code like

#if debugbuild
   system.debuglog "some message"
#endif

It means you type multiple lines of code all the time and if you forget to wrap things in the #if debugbuild then you have logging messages in your builds that maybe should have been turned off

Personally I have a module, named Debug, that has a method in it – Log

Then where ever I want a debugging message I can write

debug.log "some message"

which is also shorter

Debug.Log is implemented as (I have other overloads as well)

Sub Log(msg as string)
  #if debugbuild
    System.Log(System.LogLevelDebug, msg)
  #endif
End Sub

This way I can write my debug.log messages and know that every last one will disappear in a built app.

And I type a little bit less as well

3 Replies to “Save yourself some time”

  1. Years ago I used the same routine you mentioned, but soon discovered that the messages into the system log did NOT appear in a timely manner (realtime) nor did they always appear in the order they were issued…. That was then… this may have changed in the intervening years. But since that had been the case I came up with this piece of code instead…. which does a few things.
    1) its quick (as long as you don’t have a time critical run loop)
    2) it keeps each apps “log” in an easy to find place
    3) it is real time and sequenctial

    “`
    Public Sub Debug(msg As String)
    #if DebugBuild
    Dim f As FolderItem
    Dim t As TextOutputStream
    f=SpecialFolder.Desktop.child(pgm_name+”x.trace_log”)
    If msg=”!!!” And f.exists Then
    f.delete
    Exit Sub
    End If
    If Not f.exists Then
    t=TextOutputStream.Create(f)
    Else
    t=TextOutputStream.Append(f)
    End If
    t.write msg+EOL
    t.close
    #Else
    return
    #Endif
    End Sub
    “`

    1. Console did get weird for a while and if you didnt search for your app then not every message showed (not sure why but thats the way it worked)
      That does seem to be corrected and fast high volume logging seems to work fine now in my experience

Comments are closed.