Question

I'm currently trying to shorten my logging command because in its current form it might be difficult to create an approach that allows an easy and efficient implementation into existing projects. My current standard log command looks like this:

logger.Fatal(CurrentFunctionName+' Grid beschriften:');

And this is an example how its output looks like:

2013 10 18 15.33.17.383 [FATAL] # [01290458] UTestMain.TFormMainTest.TitelGridRows (Line 229, "UPTestMain.pas") # Actual Log Message

So I thought about putting my jcl-based CurrentFunctionName-method ( jcldebug.GetLocationInfoStr(Caller(1)) ) directly into the loggers' unit. It worked but due to its intended function it only gave information about the methods within the loggers unit. This is how I think it might be possible, but I haven't yet stumbled across the right way to do this:

    procedure TLogger.Fatal(const AMsg : String);
begin
   log(TLevelUnit.FATAL,  PreviousFunctionName + AMsg);
end;

So instead of getting the name of the current method I want to get the name of the previous method where the call of this logging-command originates. I think with suffice debug informations this should be possible, but currently I can't see how to get this working.

Was it helpful?

Solution

To get the name of the caller instead of the current function, pass 2 instead of 1 when you call Caller. You can go as far along the call stack as you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top