Answers for "logi in oracle"

SQL
0

log file oracle

CREATE OR REPLACE
PROCEDURE "WRITELOG" (LOGLEVEL IN VARCHAR2, LOGCONTEXT IN VARCHAR2, LOGMESSAGE IN VARCHAR2)
AUTHID CURRENT_USER
AS
    F1 UTL_FILE.FILE_TYPE;
    PRAGMA AUTONOMOUS_TRANSACTION;
    LOG_DIR VARCHAR2;
    LOG_FILENAME VARCHAR2;
BEGIN
    LOG_DIR := 'MYLOG_DIR';
    LOG_FILENAME := 'mylog';
    F1 := UTL_FILE.FOPEN(LOG_DIR, TO_CHAR(SYSDATE,'YYYY-MM-DD') || '_' ||  LOG_FILENAME ||'.log','a');
    UTL_FILE.PUT_LINE(F1, TO_CHAR(SYSDATE,'DD-MM-YYYY HH:MI:SS AM') || ' - [' || LOGLEVEL || '] ' || LOGCONTEXT || ': ' || LOGMESSAGE);
    UTL_FILE.FCLOSE(F1);

EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('ERROR: ' || TO_CHAR(SQLCODE) || SQLERRM);
      IF UTL_FILE.IS_OPEN(F1) THEN
        UTL_FILE.FCLOSE(F1);
      END IF;
END;
Posted by: Guest on April-06-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language