Simple override for Windows.OutputDebugString which adds a timestamp, thread id and memory, and an overloaded string version to get rid of those pesky pChar casts.
The output shows up in the in the BDS Event Log, or it can be captured while running live with Sysinternal’s DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx).
CustomDebugOut.pas – http://pastebin.com/GM7DE18L
7 thoughts on “OutputDebugString override”
me likey this one!
Why the critical section? Windows OutputDebugString already does its internal synchronization: http://stackoverflow.com/questions/509498/in-delphi-is-outputdebugstring-thread-safe
Ondrej Kelle – Actually, that one is experimental. After logging millions and millions of multi-threaded lines with DebugView, it is clear that lines are dropped. Trying to figure out if this helps. If not, I’ll have to blame DebugView.
I am actually considering doing direct logging to disk by capturing the string and passing it to a background thread which burst-writes the log for minimum IO overhead. Having access to full firehose logged data is gold for researching issues in real-time.
Thanks for the heads up, Lars Fosdal. I’ve had some trouble with OutputDebugString under heavy load, too, but I don’t remember what the problem was. Another thing to be aware of: because of the synchronization, using the API will affect the behaviour of your multi-threaded app.
Indeed it will. Fortunately, I am mostly shuffling db data and have “all the time in the world” 😉
[ Having access to full firehose logged data is gold for researching issues in real-time.] said by Lars Fosdal . I totally agree with this! I did that with our real time software, such as city metro system. 1 log file per hour, and remain files within 1 month. However, logging info is lesser than outputdbugstring shown in debugview. Logging to disk should be an optional.
You must log in to post a comment.