1 PACKAGE BODY OE_DEBUG_PUB AS
2 /* $Header: OEXPDBGB.pls 120.0 2005/06/01 02:46:00 appldev noship $ */
3
4
5 Function Set_Debug_Mode(P_Mode in varchar2) Return Varchar2 IS
6 rtn_val Varchar2(100);
7 Begin
8 if P_MODE = 'FILE' then
9 G_DEBUG_MODE := 'FILE';
10 if G_FILE is null then
11 select substr('l'|| substr(to_char(sysdate,'MI'),1,1)
12 || lpad(oe_debug_s.nextval,6,'0'),1,8) || '.dbg'
13 into G_FILE
14 from dual;
15 G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'w');
16 UTL_FILE.Put_Line(G_FILE_PTR,'Session Id:'||userenv('SESSIONID'));
17
18 -- Start Other Debuggers.
19
20 WSH_DEBUG_INTERFACE.Start_Debugger
21 (p_dir_name => G_DIR,
22 p_file_name => G_FILE,
23 p_file_handle => G_FILE_PTR);
24
25 INV_DEBUG_INTERFACE.Start_INV_Debugger
26 (p_dir_name => G_DIR,
27 p_file_name => G_FILE,
28 p_file_handle => G_FILE_PTR);
29 end if;
30 rtn_val := G_DIR || '/' || g_file;
31 elsif P_MODE = 'CONC' then
32 G_DEBUG_MODE := 'CONC';
33 rtn_val := null;
34 WSH_DEBUG_INTERFACE.Start_Debugger
35 (p_dir_name => NULL,
36 p_file_name => NULL,
37 p_file_handle => NULL);
38
39 INV_DEBUG_INTERFACE.Start_INV_Debugger
40 (p_dir_name => NULL,
41 p_file_name => NULL,
42 p_file_handle => NULL);
43 else
44 G_DEBUG_MODE := 'TABLE';
45 rtn_val := null;
46 end if;
47
48 BEGIN
49 oe_debug_pub.setdebuglevel(G_Debug_Level);
50 EXCEPTION
51
52 WHEN OTHERS THEN
53
54 OE_DEBUG_PUB.G_DEBUG_LEVEL := 0;
55 oe_debug_pub.setdebuglevel(G_Debug_Level);
56
57 END;
58 oe_debug_pub.debug_on;
59
60 return(rtn_val);
61 Exception when others then
62 G_DEBUG_MODE := 'TABLE';
63 rtn_val := null;
64 return(rtn_val);
65 End;
66
67
68 PROCEDURE Initialize
69 IS
70 BEGIN
71
72 G_Debug_tbl.DELETE;
73 G_Debug_count := 0;
74 G_Debug_index := 0;
75
76 END Initialize;
77
78
79 Procedure Debug_ON
80 IS
81 Begin
82 OE_DEBUG_PUB.G_DEBUG := FND_API.G_TRUE;
83 End Debug_On;
84
85
86 Procedure Debug_OFF
87 IS
88 Begin
89 OE_DEBUG_PUB.G_DEBUG := FND_API.G_FALSE;
90 End Debug_Off;
91
92
93 Function ISDebugOn
94 Return Boolean IS
95 Begin
96 if OE_DEBUG_PUB.G_DEBUG = FND_API.G_TRUE then
97 RETURN(TRUE);
98 else
99 RETURN(FALSE);
100 end if;
101 End ISDebugOn;
102
103
104 -- FUNCTION Count_Debug
105 --
106 -- Usage Used by API callers and developers to find the count
107 -- of Debugs in the message list.
108 -- Desc Returns the value of G_Debug_count
109 --
110 -- Parameters None
111 --
112 -- Return NUMBER
113
114 FUNCTION CountDebug RETURN NUMBER
115 IS
116 BEGIN
117
118 RETURN G_Debug_Count;
119
120 END CountDebug;
121
122 -- PROCEDURE Add_Debug_Msg
123 --
124 -- Usage Used to add Debugs to the global message table.
125
126 PROCEDURE Add_Debug_Msg(debug_msg in Varchar2, debug_level in Number default 5)
127 IS
128 l_fname VARCHAR2(80);
129 l_debug_msg VARCHAR2(2000);
130 l_g_miss_char VARCHAR2(12) := FND_API.G_MISS_CHAR;
131 l_replace VARCHAR2(12) := ' G_MISS_CHAR';
132 BEGIN
133
134 if NOT OE_GLOBALS.G_UI_FLAG then
135 if NOT ISDebugOn then
136
137 if nvl(fnd_profile.value('CONC_REQUEST_ID'),-1) <> -1 then
138
139 l_fname := set_debug_mode('CONC');
140 else
141 l_fname := set_debug_mode('FILE');
142 end if;
143
144 end if;
145 end if;
146
147 if (G_Debug_Level >= debug_level) then
148 if (ISDebugOn) then
149 if debug_msg is not null then
150 if G_DEBUG_MODE = 'TABLE' then
151 -- Increment Debug count
152 G_Debug_count := G_debug_count + 1;
153 -- Write Debug.
154 G_Debug_tbl(G_debug_count) := substr(debug_msg,1,G_DEBUG_LEN);
155
156 elsif G_DEBUG_MODE = 'CONC' then /* Concurrent program mode.
157 Write to the table, concurrent pgm output file and
158 also to the debug log file */
159 -- G_Debug_count := G_debug_count + 1;
160 -- G_Debug_tbl(G_debug_count) := substr(debug_msg,1,G_DEBUG_LEN);
161 l_debug_msg := substr(replace(debug_msg,l_g_miss_char,l_replace),1,2000);
162 FND_FILE.put_line(FND_FILE.LOG, l_debug_msg);
163 if G_FILE is not null then
164 utl_file.put_line(G_FILE_PTR, debug_msg);
165 utl_file.fflush(G_FILE_PTR);
166 end if;
167 else -- debug mode
168 l_debug_msg := substr(replace(debug_msg,l_g_miss_char,l_replace),1,2000);
169 utl_file.put_line(G_FILE_PTR, l_debug_msg);
170 utl_file.fflush(G_FILE_PTR);
171 end if;
172 end if; -- debug_msg is not null
173 end if; -- debug on
174 end if;-- debug level is big enough
175
176 Exception
177 WHEN OTHERS then
178 if g_debug_mode IN ('TABLE','CONC') then
179 G_DEBUG_COUNT := G_DEBUG_COUNT - 1;
180 end if;
181 debug_off; -- Internal exception turn the debug off
182 END add_debug_msg; -- Add
183
184 -- PROCEDURE Add
185 --
186 -- Usage Used to add Debugs to the global message table.
187
188 PROCEDURE Add(debug_msg in Varchar2, debug_level in Number default 5)
189 IS
190 BEGIN
191
192 --
193 -- Bug 2325973: Eliminated all local variables and moved rest of
194 -- the code to Add_Debug_Msg.
195 --
196 -- For the scenario when debugging is OFF (g_debug_level=0), this
197 -- procedure should execute only 2 statements: 'IF G_DEBUG_LEVEL = 0'
198 -- and 'RETURN'. NO FURTHER CODE OR VARIABLES SHOULD BE ADDED IN
199 -- THIS PROCEDURE!
200 --
201
202 IF G_DEBUG_LEVEL = 0 THEN
203 RETURN;
204 ELSIF G_DEBUG_LEVEL IS NULL THEN
205 G_Debug_Level := to_number(nvl(fnd_profile.value('ONT_DEBUG_LEVEL'), '0'));
206 END IF;
207
208 IF G_Debug_Level > 0 THEN
209 Add_Debug_Msg(debug_msg,debug_level);
210 END IF;
211
212 EXCEPTION
213 WHEN OTHERS THEN
214 OE_DEBUG_PUB.G_DEBUG_LEVEL := 0;
215 END Add;
216
217 Procedure GetFirst(Debug_msg out NOCOPY /* file.sql.39 change */ Varchar2)
218 IS
219 BEGIN
220 resetindex;
221 if G_DEBUG_COUNT <> 0 then
222 debug_msg := G_DEbug_tbl(1);
223 g_debug_index := 1;
224 else
225 debug_msg := null;
226 end if;
227 Exception when others then
228 debug_msg := null;
229 END GetFirst;
230
231
232 Procedure GetNext(debug_msg out NOCOPY /* file.sql.39 change */ varchar2) is
233 Begin
234 if g_debug_count > g_debug_index then
235 g_debug_index := g_debug_index + 1;
236 debug_msg := G_Debug_tbl(g_debug_index);
237 else
238 debug_msg := null;
239 end if;
240 Exception when others then
241 debug_msg := null;
242 End GetNext;
243
244
245 Function ISLastMsg
246 return number is
247 Begin
248 if g_debug_count <= g_debug_index then
249 return(1);
250 else
251 return(0);
252 end if;
253 End ISLastMsg;
254
255
256 PROCEDURE DumpDebug
257 IS
258 i number := 0;
259 BEGIN
260 --dbms_output.enable(100000);
261 for i in 1..g_debug_count loop
262 --dbms_output.put_line('Number : '|| to_char(i) || ' :: ' ||
263 --G_debug_tbl(i));
264 null;
265 end loop;
266 END DumpDebug;
267
268
269 Procedure GetNextBuffer(p_debug_msg in out NOCOPY /* file.sql.39 change */ varchar2) is
270 msg_str varchar2(500);
271 i number;
272 x_buffer_len number := 0;
273 x_msg_len number := 0;
274 x_prev_index number;
275 x_msg_count number := 1;
276 begin
277 p_debug_msg := '';
278 if G_DEBUG_COUNT > 0 and g_debug_index < g_debug_count then
279 loop
280 x_prev_index := g_debug_index;
281 x_msg_len := length(G_DEbug_tbl(g_debug_index+1));
282 if (x_buffer_len + x_msg_len) < 2000 and x_msg_count <40 then
283 g_debug_index := g_debug_index + 1;
284 x_msg_count := x_msg_count + 1;
285 p_debug_msg := p_debug_msg || fnd_global.local_chr(10) || G_DEBUG_TBL(g_debug_index);
286 x_buffer_len := x_buffer_len + x_msg_len;
287 else
288 exit;
289 end if;
290 if (g_debug_index >= g_debug_count) or x_prev_index = g_debug_index then
291 exit;
292 end if;
293 end loop;
294 end if;
295 end;
296
297
298 Procedure ResetIndex is
299 begin
300 g_debug_index := 0;
301 end;
302
303
304 Procedure SetDebugLevel(p_debug_level in number)
305 IS
306 Begin
307 OE_DEBUG_PUB.G_DEBUG_LEVEL := p_debug_level;
308 Exception
309 WHEN OTHERS THEN
310 OE_DEBUG_PUB.G_DEBUG_LEVEL := 0;
311
312 End SetDebugLevel;
313
314
315 Procedure Start_ONT_Debugger
316 (p_directory IN VARCHAR2
317 ,p_filename IN VARCHAR2
318 ,p_file_handle IN UTL_FILE.File_Type
319 )
320 IS
321
322 BEGIN
323
324
325 G_DEBUG_MODE := 'FILE';
326
327 -- If the file pointer is passed use the same
328 -- else open the file passed as parameter.
329
330 -- Open the file if filename and directory are
331 -- not null.
332
333
334 IF UTL_FILE.Is_Open(p_file_handle) THEN
335
336 G_FILE_PTR := p_file_handle;
337
338 ELSIF p_filename is NOT NULL AND
339 p_directory is NOT NULL THEN
340
341 G_DIR := p_directory;
342 G_FILE := p_filename;
343
344 G_FILE_PTR := UTL_FILE.Fopen(G_DIR, G_FILE, 'w');
345
346 END IF;
347
348 UTL_FILE.Put_Line(G_FILE_PTR,'Session Id:'||userenv('SESSIONID'));
349
350 BEGIN
351 OE_DEBUG_PUB.Setdebuglevel(5);
352 EXCEPTION
353 WHEN OTHERS THEN
354 OE_DEBUG_PUB.G_DEBUG_LEVEL := 0;
355 OE_DEBUG_PUB.Setdebuglevel(G_Debug_Level);
356
357 END;
358
359 OE_DEBUG_PUB.Debug_On;
360
361 Exception
362 WHEN OTHERS THEN
363 NULL;
364
365 END Start_ONT_Debugger;
366
367 Procedure Stop_ONT_Debugger
368 IS
369 BEGIN
370 OE_DEBUG_PUB.G_DEBUG_LEVEL := 0;
371 END Stop_ONT_Debugger;
372
373 END OE_DEBUG_PUB;