3

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.

TheLax
  • 93
  • 13
  • 1
    look how JCL Exception Dialog works and what prerequisites are. Then you can do the same. But don't expect it to be fast - it will not. http://stackoverflow.com/questions/347365/ and http://pilif.github.io/2002/12/jcldebug/ – Arioch 'The Oct 21 '13 at 13:48

1 Answers1

5

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.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Earlier today I tried several changes concerning the parameters for `caller` . But it seems I messed up checking the right log files. Thanks. – TheLax Oct 21 '13 at 14:37