Thanks for the question, Nikhil.
Asked: February 01, 2017 - 5:58 am UTC
Last updated: February 01, 2017 - 10:36 am UTC
Version: 11.2
Viewed 1000+ times
You Asked
Hi Chris/Connor,
We want to create a Application Error Logger table.
Here is the Table & Column specification.
Could you suggest any better approach to do this(if any)
TB_SAVE_EXCEPTIONS with below 5 columns:
1. CALLER (will hold Procedure, Function or PKG name, VARCHAR2(60 char))
2. SQL_ERROR_CODE (will hold SQL error code returned by SQLERRM, VARCHAR2(10 char))
3. ERROR_TRACE (will hold error trace returned by DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, VARCHAR2(4000 char))
4. ADDITIONAL_INFORMATION (will hold module specific additional information to identify the data for which exception occurred, VARCHAR2(4000 char))
5. CREATED_ON (DATE)
We write insert queries in callers or introduce a procedure SP_SAVE_EXCEPTIONS (with pragma autonomous transaction + insert query + commit)
The code in callers would look something like this -
EXCEPTION
WHEN OTHERS THEN
error_count := SQL%BULK_EXCEPTIONS.count;
DBMS_OUTPUT.put_line('Number of failures: ' || error_count);
FOR i IN 1 .. error_count
LOOP
CAll to SP_SAVE_EXCEPTIONS
DBMS_OUTPUT.put_line('Error: ' || i || ' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index || ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
END LOOP;
and Chris said...
Rather than building your own custom logging routine, I'd use the open source library Logger:
https://github.com/OraOpenSource/Logger This includes logger.log_error which already stores the call stack etc. And it includes a bunch procedures for more general instrumentation.
Is this answer out of date? If it is, please let us know via a Comment