I posted yesterday induced-garbage-collection and wrote I would look for information on DebugLog.
I can find nothing substantial. Only pieces of code that apparently trap information.
I found a couple of mentions in the blog of logging.
I know it’s been around for a while but I cannot find any explanation of it.
There
Things I am missing are:
How different is it from the debugger’s pane?
Is it always available?
How much detail do I need to go in to trap a Boolean?
What does the output look like?
What if want to trap an array?
Are there other similar features?
How do you know CurrentMethodName from System is correct one to use?
What can I trap from a class? Every piece of info?
What can I not get?
Simply put, you include in your code stuff like this:
System.DebugLog "Creating Dictionary"
dim d as new Dictionary
if d is nil then
System.DebugLog "... but it's nil. Wut?!?"
end if
System.DebugLog "Assigning values to Dictionary"
...
When your code runs, it logs those messages so you can examine them in realtime. Because you define the messages and where they appear, you can use this technique to make sure your code is doing what you think it’s doing and that variables are what you think they are. (Or anything else you’d find helpful.)
The easiest way to get to that log is in the IDE at the bottom of the code editor. There are three tabs there, one for the search pane, the next for compiler messages, and the third for the log. While your app is running through the IDE, open that third pane and watch the messages fly.
In your case, if there is a race condition that isn’t showing up when you drop into the debugger, you should be able to craft messages to expose it.
I have mentioned this before… But a while back I tried to use System.DebugLog and found that either messages never showed up, lagged way behind the event, or in some cases appeared out of order. So I gave up… and created my own solution.
While its not elegant, I found that it never lagged, never was out of order, and the performance hit to the running app was acceptable during testing/debugging (as in neglible)
I add this method to my code, and call it instead of “System.DebugLog”
Public Sub debug(msg As String,force as Boolean=false)
//return // <---- just uncomment this line to deactivate the Debug logger across the entire app
Dim f As FolderItem
Dim t As TextOutputStream
f=specialfolder.desktop.child("name_of_my_program.trace_log")
If msg="!!!" Then
If f.exists Then f.delete
Exit Sub
End If
//
#If DebugBuild Then
force=True
#EndIf
If force Then
If Not f.exists Then
t=TextOutputStream.Create(f)
Else
t=TextOutputStream.Append(f)
End If
t.write Str(Ticks)+":"+msg+EndOfLine
t.close
End If
End Sub
then to use Kems example
DEBUG "Creating Dictionary"
dim d as new Dictionary
if d is nil then
DEBUG "... but it's nil. Wut?!?"
end if
DEBUG "Assigning values to Dictionary"
Thanks to both.
I will try them but the nagging question of “Race Conditions” is there.
I don’t use threads so I don’t have the option waiting until it’s complete.
I also have no idea how to debug for that.
Suggestions?
To whom are you asking that question? If to me, then yes, yes I do, but if you read my post, you will see my specific reasons for not using this method, it is very very slow, and it is not in synch with the events as they happen
I don’t see what the difficulty is. I have a global (debugfl) which I can clear/set with a button. So if I want to log something, anywhere in the app, I can do:
if (app.debugfl=true) then
// Write to log here
end if
Since my app has a textarea in which it reports things to the user, I can just use that to report debug output. Here is an actual example:
if (app.debugfl=true) then writeLogging ("Initialise at 2 - filetype: " + mboxtype.ToText + " dbpath: '" + dbpath + "'")
Normally when the app runs, debugfl is false, of course. I have about 100 statements like this for different reasons scattered throughout the app. When developing this I didn’t know about system.debuglog, but I still prefer not to use that as the app itself can display the debugging output.