Skip to content

packages tree.get_call_stack

Jan Kvetina edited this page Oct 9, 2020 · 2 revisions

tree.get_call_stack

Repository spec: tree.get_call_stack, body: tree.get_call_stack


Signature

FUNCTION get_call_stack
RETURN logs.message%TYPE;
Show code (20 lines)

FUNCTION get_call_stack
RETURN logs.message%TYPE
AS
    out_stack       VARCHAR2(32767);
    out_module      logs.module_name%TYPE;
BEGIN
    -- better version of DBMS_UTILITY.FORMAT_CALL_STACK
    FOR i IN REVERSE 2 .. UTL_CALL_STACK.DYNAMIC_DEPTH LOOP  -- 2 = ignore this function
        out_module := UTL_CALL_STACK.CONCATENATE_SUBPROGRAM(UTL_CALL_STACK.SUBPROGRAM(i));
        CONTINUE WHEN
            UTL_CALL_STACK.OWNER(i) != USER                                 -- different user (APEX)
            OR UTL_CALL_STACK.UNIT_LINE(i) IS NULL                          -- skip DML queries
            OR REGEXP_LIKE(out_module, 'UT(\.|_[A-Z0-9_]*\.)[A-Z0-9_]+')    -- skip unit tests
            OR (out_module = internal_log_fn AND i <= 2);                   -- skip target function
        --
        out_stack := out_stack || out_module || ' [' || UTL_CALL_STACK.UNIT_LINE(i) || ']' || CHR(10);
    END LOOP;
    --
    RETURN SUBSTR(out_stack, 1, tree.length_message);
END;

Clone this wiki locally