rules repository

G-5010

🆓
Warning

Try to use a error/logging framework for your application.

Reason

Having a framework to raise/handle/log your errors allows you to easily avoid duplicate application error numbers and having different error messages for the same type of error.

This kind of framework should include

  • Logging (different channels like table, mail, file, etc. if needed)
  • Error Raising
  • Multilanguage support if needed
  • Translate Oracle Database error messages to a user friendly error text
  • Error repository

Based on static code analysis, it is difficult to identify the places where a logging call would be beneficial. However, when we see a dbms_output call, we make two assumptions. Firstly, this is a good place for a logging call. Secondly, debugging capabilities can be improved by using a logging framework instead, which provides logging output via another channel.

Therefore, we decided to look for dbms_output calls.

Example

Non-Compliant Example

declare
   co_start constant logger_logs.text%type := 'start';
   co_end   constant logger_logs.text%type := 'end';
begin
   sys.dbms_output.put_line(co_start);
   -- some processing
   sys.dbms_output.put_line(co_end);
end;
/
Issues
LineColumnMessage
54Use a logging framework instead of DBMS_OUTPUT.
74Use a logging framework instead of DBMS_OUTPUT.

Compliant Solution - ★★★★★

declare
   -- see https://github.com/OraOpenSource/Logger
   co_start constant logger_logs.text%type  := 'start';
   co_end   constant logger_logs.text%type  := 'end';
   co_scope constant logger_logs.scope%type := 'demo';
begin
   logger.log(co_start,co_scope);
   -- some processing
   logger.log(co_end,co_scope);
end;
/

References