-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_mgmt_body.sql
182 lines (141 loc) · 4.45 KB
/
log_mgmt_body.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
create or replace package body log_mgmt as
--
-- V0.1
--
procedure msg(
msg clob,
skip_stack_levels integer := 0
) as -- {
pragma autonomous_transaction;
call varchar2(4000);
lin number;
stack_levels integer := 2 + skip_stack_levels;
begin
call := utl_call_stack.concatenate_subprogram(utl_call_stack.subprogram( stack_levels ));
lin := utl_call_stack.unit_line ( stack_levels ) ;
insert into log (
msg,
call,
lin,
task_exec_id
)
values (
msg,
call,
lin,
task_mgmt.cur_task
);
commit;
end msg; -- }
procedure exc( -- {
msg clob := null,
reraise boolean := true
)
as
pragma autonomous_transaction;
call varchar2(4000);
lin number;
cs integer;
es integer;
sqlerrm_ varchar2(500) := sqlerrm;
begin
call := utl_call_stack.concatenate_subprogram(utl_call_stack.subprogram( 2 ));
lin := utl_call_stack.unit_line ( 2 ) ;
cs := dump_call_stack(skip_stack_levels => 0);
es := dump_error_stack;
insert into log (
msg,
call,
lin,
exc,
task_exec_id
)
values (
-- 'error_depth: ' || utl_call_stack.error_depth || ', ' ||
case when msg is not null then msg || chr(10) end ||
'Call stack: ' || cs || ', error stack: ' || es || chr(10) ||
sqlerrm_ || chr(10) ||
dbms_utility.format_error_backtrace,
call,
lin,
'!',
task_mgmt.cur_task
);
commit;
if reraise then
raise_application_error(-20800, case when msg is not null then msg else sqlerrm_ end);
end if;
end exc; -- }
function dump_error_stack return integer is -- {
pragma autonomous_transaction;
id_ integer;
begin
insert into error_stack(ts) values (systimestamp) returning id into id_;
for d in 1 .. utl_call_stack.error_depth loop
insert into error_stack_entry(nr, msg, error_stack_id) values (
utl_call_stack.error_number(d),
utl_call_stack.error_msg (d),
id_
);
end loop;
commit;
return id_;
end dump_error_stack; -- }
function dump_call_stack(skip_stack_levels integer := 0) return integer is -- {
pragma autonomous_transaction;
stack_levels integer := 2 + skip_stack_levels;
id_ integer;
dn integer;
qn utl_call_stack.unit_qualified_name;
pkg varchar2(128);
ow varchar2(128);
sp varchar2(128);
ul integer;
ed integer;
bd integer;
i integer;
btu varchar2(128);
begin
insert into call_stack(ts) values (systimestamp) returning id into id_;
dn := utl_call_stack.dynamic_depth;
for d in stack_levels .. dn loop
ow := utl_call_stack.owner(d);
qn := utl_call_stack.subprogram(d);
sp := qn(qn.count);
ul := utl_call_stack.unit_line(d);
insert into call_stack_entry (owner, package, subprogram, line, flg, depth, call_stack_id)
values (
ow,
qn(1),
sp,
ul,
case when d = stack_levels then '*' end,
dn - d,
id_
);
end loop;
ed := utl_call_stack.error_depth;
bd := utl_call_stack.backtrace_depth;
for d in 1 .. bd loop
btu := utl_call_stack.backtrace_unit(d);
i := instr(btu, '.');
ow := substr(btu, 1, i-1);
pkg := substr(btu, i+1);
ul := utl_call_stack.backtrace_line(d);
insert into call_stack_entry (owner, package, subprogram, line, flg, depth, call_stack_id)
values (
ow,
pkg,
null,
ul,
'!',
bd - d + stack_levels,
id_
);
end loop;
commit;
return id_;
end dump_call_stack; -- }
end log_mgmt;
/
show errors