Этим мы сейчас и займемся.
Для начала создадим сиквенс, который будет генерировать уникальные идентификаторы для наших логов:
CREATE SEQUENCE logs_tab_seq START WITH 1 MAXVALUE 999999999999 MINVALUE 1 NOCYCLE NOCACHE NOORDER /
Теперь, очередь за таблицей, в которой будут храниться логи:
create table logs_tab ( id number(32) not null, date_insert date not null, message varchar2(4000) null, message_big clob null, group_id varchar2(16) null, sessionid number(16) not null, os_user varchar2(128) not null ); comment on table logs_tab is 'Table with logs (filled procedure write_log, cleaned - clear_log)'; comment on column logs_tab.id is 'ID of record'; comment on column logs_tab.date_insert is 'Date insert records into the table'; comment on column logs_tab.message is 'A short message is less than 4000 characters'; comment on column logs_tab.message_big is 'A Long message (to be filled, if in the short does not fit)'; comment on column logs_tab.group_id is 'Group ID records (selected by the user ID)'; comment on column logs_tab.sessionid is 'ID of session'; comment on column logs_tab.os_user is 'User''s name in OS'; alter table logs_tab add constraint logs_tab_pk primary key (id) /
Процедура логирования:
create or replace procedure write_log(p_message in varchar2, p_group_id in varchar2 default null) is pragma autonomous_transaction; v_message_big clob; v_message varchar2(4000); v_sessionid number(16); v_os_user varchar2(128); begin if length(p_message) < 4000 then v_message := p_message; v_message_big := null; else v_message := null; v_message_big := p_message; end if; select userenv('sessionid') into v_sessionid from dual; select sys_context('userenv', 'os_user') into v_os_user from dual; insert into logs_tab (id, date_insert, message, message_big, group_id, sessionid, os_user) values (logs_tab_seq.nextval, sysdate, v_message, v_message_big, p_group_id, v_sessionid, v_os_user); commit; end write_log; /
Комментариев нет:
Отправить комментарий