By default it will return the location from where it was called, so this -

function test2() {

Logger.log('my logged message ' + JSON.stringify(whereAmI()));

}

logs this

my logged message {"caller":"test2","line":"120","file":"Code"}

Reporting a different stack level

Imagine you have some shared function that's called from multiple functions, and you have a Logger.log() in your shared function. The example above will show location information about the shared function, but what you really want to log is where shared was called from (and maybe even higher up than that). You can do this by passing a stack level to whereAmI() and it will report back up the call stack as required.

this

function shared() {

Logger.log('my logged message ' + JSON.stringify(whereAmI()));

}

will give this

my logged message {"caller":"shared","line":"107","file":"Code"}

whereas running test4 & test5 - with a stack level of 2 passed to whereAmI(2), will give location information about who is calling shared().