From an XQuery program I want to log the name of the current function. Is there a way to get the name of the current function without throwing an exception?
I can get the function information by throwing an exception and logging stack frame information. But is there a way to get the current function name without throwing an exception like this
xquery version "1.0-ml";
declare function local:logStuff( $str as xs:string )
{
try { fn:error() }
catch( $ex ) {
let $frame := ($ex/error:stack/error:frame)[2]
let $function as xs:string := $frame/error:operation
let $line as xs:numeric := $frame/error:line
let $column as xs:numeric := $frame/error:column
return
fn:concat(
"message: '", $str, "' In Function: ", $function,
" line: ", $line, " column: ", $column
)
}
};
declare function local:callingFunction()
{
local:logStuff( "I want to log this line of code with function info.")
};
local:callingFunction()
,
"And continue with the program ..."