Log Sub-Program Parameter Values Using LOG4PL/SQL Framework In Oracle Database 19c

reference_partition

LOG4PLSQL is an open source tool that uses PL/SQL framework to log into PL/SQL code package,function,web application,procedure, trigger and various oracle tools such as reports,forms etc.

Logging is very important part of development life cycle for any process or application. These logs are important for tracing functional events,data and operations.Logs are also used for code debugging and in testing or maintenance phase to understand unforeseen events such as system crash,quit or launch.It is considered as a very time-consuming tedious job as all the logs during the development strategy have to be considered which utilizes vital computer memory or resources.

One common logging requirement that many developer wish – is to log both INCOMING & OUTGOING parameter values in a sub program.

--Base Table
SQL> SELECT * FROM emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

PROCEDURE

SQL> CREATE OR REPLACE PROCEDURE course.log4plsql_proc_param_1 (p_empno course.emp.empno%TYPE,p_sal OUT course.emp.sal%TYPE)
  2  IS
  3      pctx LOGGER.PLOGPARAM.LOG_CTX := LOGGER.PLOG.INIT(plevel => LOGGER.PLOG.LDEBUG);
  4  BEGIN
  5      LOGGER.PLOG.INFO (pctx,'EMPNO Passed - '||p_empno);
  6
  7      SELECT sal
  8      INTO p_sal
  9      FROM course.emp
 10      WHERE empno = p_empno;
 11
 12      LOGGER.PLOG.INFO (pctx,'SAL Retrieved - '||p_sal);
 13  END;
 14  /

Procedure created.

SQL> DECLARE
  2   nsal course.emp.sal%TYPE;
  3   nempno course.emp.empno%TYPE;
  4  BEGIN
  5   nempno := 7839;
  6
  7   course.log4plsql_proc_param_1(nempno,nsal);
  8
  9   DBMS_OUTPUT.PUT_LINE('SAL Displayed In DBMS_OUTPUT Interface ::: '||nsal);
 10  END;
 11  /

--OUTPUT :::
SAL Displayed In DBMS_OUTPUT Interface ::: 5000

FUNCTION

SQL> CREATE OR REPLACE FUNCTION course.log4plsql_func_param_1 (p_empno course.emp.empno%TYPE)
  2  RETURN NUMBER
  3  IS
  4      pctx LOGGER.PLOGPARAM.LOG_CTX := LOGGER.PLOG.INIT(plevel => LOGGER.PLOG.LDEBUG);
  5  nsal course.emp.sal%TYPE;
  6  BEGIN
  7      LOGGER.PLOG.INFO (pctx,'EMPNO Passed - '||p_empno);
  8
  9      SELECT sal
 10      INTO nsal
 11      FROM course.emp
 12      WHERE empno = p_empno;
 13
 14      LOGGER.PLOG.INFO (pctx,'SAL Retrieved - '||nsal);
 15
 16      RETURN nsal;
 17  END;
 18  /

Function created.

SQL> SELECT course.log4plsql_func_param_1(7839) result FROM dual;

    RESULT
----------
      5000

Shoumadip Das

Hi Folks, I am Shoumadip Das hailing from Kolkata, India welcoming you to explore my blog www.oraclemasterpiece.com. I am a self motivated and successful professional working in a leading IT Giant for more than 10 years.My area of expertise includes –

  • Oracle Database Programming (SQL & PL/SQL)
  • Perl Programming
  • Unix Programming

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *