Logger
Logger copied to clipboard
SQLERRM isn't being logged
SQLERRM should be logged (via dbms_utility.format_error_backtrace) but it isn't. Simple test case:
create or replace procedure p_test as
l_temp pls_integer;
begin
raise_application_error(-20001, 'todo');
select 1
into l_temp
from dual where 1/0 = 1;
exception
when others then
-- dbms_output.put_line('ERROR: ' || sqlerrm);
-- dbms_output.put_line('ERROR: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE );
logger.log('ERROR:', 'mdsouza');
end;
/
Is another error happening ahead of this or why isn't it rendering the error?
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE holds the line number of the error. DBMS_UTILITY.FORMAT_ERROR_STACK still holds the last error message.
I often concat the two to make sure I got everything.
Is it better to use logger.log_error procedure instead of logger.log to save the error? I suggest adding a detection of the presence of an error in the logger.log and if necessary, save the error data:
log_internal(
p_text => p_text,
p_log_level => logger.g_debug,
p_scope => p_scope,
p_extra => p_extra,
p_callstack => CASE
SQLCODE = 0 THEN dbms_utility.format_call_stack
ELSE dbms_utility.format_error_stack() || gc_line_feed || dbms_utility.format_error_backtrace
END,
p_params => p_params);