-- logger2.sql

CREATE OR REPLACE PACKAGE logger AS
  PROCEDURE open(file VARCHAR2);
  PROCEDURE write(line VARCHAR2);
  PROCEDURE close;
END;
/

CREATE OR REPLACE PACKAGE BODY logger AS
  logfile UTL_FILE.FILE_TYPE;
 
  PROCEDURE open(file VARCHAR2) AS
  BEGIN
   logfile := UTL_FILE.FOPEN('LOGDIR', file, 'a');
  END open;

  PROCEDURE write(line VARCHAR2) AS
    time VARCHAR2(30);
  BEGIN
    time := TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS');
    UTL_FILE.PUT_LINE(logfile, time || ': ' || line);
  END write;

  PROCEDURE close AS
  BEGIN
    UTL_FILE.FCLOSE(logfile);
  END close;
END;
/
