Some of these features are already included in our TSynLog
class , which runs from Delphi 5 to XE2.
This is a complete Open Source and works with Delphi XE2, so you have all the necessary source code. And it contains an interception exception and a stack trace.
It allows you to track the trace as follows:
procedure TestPeopleProc; var People: TSQLRecordPeople; Log: ISynLog; begin Log := TSQLLog.Enter; People := TSQLRecordPeople.Create; try People.ID := 16; People.FirstName := 'Louis'; People.LastName := 'Croivébaton'; People.YearOfBirth := 1754; People.YearOfDeath := 1793; Log.Log(sllInfo,People); finally People.Free; end; end;
It will be registered as such:
20120520 13172261 + 000E9F67 SynSelfTests.TestPeopleProc (784) 20120520 13172261 info {"TSQLRecordPeople(00AB92E0)":{"ID":16,"FirstName":"Louis","LastName":"Croivébaton","Data":"","YearOfBirth":1754,"YearOfDeath":1793}} 20120520 13172261 - 000EA005 SynSelfTests.TestPeopleProc (794) 00.002.229
I.e:
- You have line numbers and a method name;
- You have the exact time spent on the method (00.002.229);
- It is very easy to show any result (here the class is even serialized as JSON directly, and you can do the same with any data, even records);
- Methods can be nested, and there is also a profiling tool available in our log viewer - that is, you can get in which methods most of the time is spent on the client side from the log file;
- You can easily add a stack trace or any other necessary information;
- Our code is very optimized for speed: for example. it uses the
interface
for the auto-vacation function, just like you, but it will not allocate memory, because it uses the trick "fake reference counter", - Of course, the definition of the
Log
variable on the stack is optional: if you only need to trace the input / TSQLLog.Enter
method, just write TSQLLog.Enter
. The local variable Log
used to easily embed additional information into the method ( Log.Log(sllInfo,People)
).
Note that debugging information (i.e. method name and line numbers) is extracted from the proprietary highly optimized binary conversion of the .map
file generated at compile time. It will be much smaller than .map
itself (for example, 900 KB .map
→ 70 KB .mab, which can be easily embedded in exe), therefore it is smaller than the format used by JCL or MadExcept, and also smaller than the information embedded in Delphi compilation time.
I don’t think having a “result” hardcoded in the “Enter” method is worth it. This will add a lot of coding (for example, switching to TValue
takes a lot of time), for little benefit - most of the time you need to know much more than the result.
source share