Save yourself some time

I see a lot of times people write code like

#if debugbuild
   system.debuglog "some message"

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)
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
    If msg=”!!!” And f.exists Then
    Exit Sub
    End If
    If Not f.exists Then
    End If
    t.write msg+EOL
    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.