DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_DEBUG_PKG

Source


1 PACKAGE BODY FA_DEBUG_PKG as
2 /* $Header: FADEBUGB.pls 120.4 2005/06/25 00:34:42 snarayan ship $ */
3 
4 -- GLOBAL VARIABLES
5 --
6 -- Debug_Rec_Type  : Record to store debug messages
7 --
8 -- fname	   : calling function name
9 --
10 -- data		   : debug message
11 --
12 
13 g_log_statement_level      CONSTANT NUMBER   := FND_LOG.LEVEL_STATEMENT;
14 g_log_procedure_level      CONSTANT NUMBER   := FND_LOG.LEVEL_PROCEDURE;
15 g_log_event_level          CONSTANT NUMBER   := FND_LOG.LEVEL_EVENT ;
16 g_log_exception_level      CONSTANT NUMBER   := FND_LOG.LEVEL_EXCEPTION;
17 g_log_error_level          CONSTANT NUMBER   := FND_LOG.LEVEL_ERROR;
18 g_log_unexpected_level     CONSTANT NUMBER   := FND_LOG.LEVEL_UNEXPECTED;
19 g_log_runtime_level        NUMBER   := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
20 g_calling_routine varchar2(150);
21 
22 TYPE  Debug_Rec_Type IS RECORD
23 ( 	fname		VARCHAR2(30)	:= NULL,
24   	data		VARCHAR2(225)	:= NULL
25 );
26 
27 -- Debug_Tbl_Type  : A global table to store all debug messages
28 --
29 TYPE Debug_Tbl_Type IS TABLE OF Debug_Rec_Type
30  INDEX BY BINARY_INTEGER;
31 
32 FA_DEBUG_TABLE		Debug_Tbl_Type;
33 
34 -- Index used to keep track of the last fetched
35 
36 FA_DEBUG_INDEX		NUMBER	:= 0;
37 
38 -- Global variable holding the message count
39 
40 FA_DEBUG_COUNT		NUMBER	:= 0;
41 
42 -- Global variable holding debug flag
43 
44 FA_DEBUG_FLAG		varchar2(3) := 'NO';
45 FA_DEBUG_FILE		varchar2(3) := 'NO';
46 
47 g_print_debug boolean := fa_cache_pkg.fa_print_debug;
48 
49 -- Procedure  	Initialize
50 --
51 -- Usage	Used by server program to intialize the global
52 --		debug message table and set the debug flag
53 --
54 
55 PROCEDURE Initialize
56 IS
57   l_request_id NUMBER;
58   l_dir VARCHAR2(200);
59   l_file VARCHAR2(200);
60   l_dirfile VARCHAR2(200);
61 BEGIN
62     --if fnd_profile.value('PRINT_DEBUG') = 'Y' then
63     if (g_print_debug) then
64 	FA_DEBUG_FLAG := 'YES';
65     end if;
66     FA_DEBUG_TABLE.DELETE;
67     FA_DEBUG_COUNT := 0;
68     FA_DEBUG_INDEX := 0;
69 
70     --
71     -- Initialization for debugging to a file
72     --
73     if fa_debug_flag <> 'YES' then
74       -- File Debugging should only be enabled if PRINT_DEBUG is also enabled
75       fa_debug_file := 'NO';
76 
77     elsif fa_debug_file <> 'YES' then
78       -- Also, only initialize file debugging once
79 
80       --l_dirfile := fnd_profile.value('FA_DEBUG_FILE');
81       l_dirfile := fa_cache_pkg.fa_debug_file;
82       if l_dirfile is not null then
83 	-- Do not set up file/dir info if this is a concurrent program
84 	-- FND_FILE will automatically place the debug messages to
85 	-- the concurrent program's log file.
86 	--l_request_id := to_number(fnd_profile.value('CONC_REQUEST_ID'));
87         l_request_id := fnd_global.conc_request_id;
88 	if l_request_id is null or l_request_id <= 0 then
89 	  l_dir := substr(l_dirfile, 1, instr(l_dirfile, ' ')-1);
90 	  l_file := substr(l_dirfile, instr(l_dirfile, ' ')+1);
91 	  if l_dir is not null and l_file is not null then
92 		fnd_file.put_names(l_file||'.log', l_file||'.out', l_dir);
93 	  end if;
94 	end if;
95 
96 	fa_debug_file := 'YES';
97 	fnd_file.put_line(fnd_file.log, 'Starting debug session....');
98       end if;
99     end if;
100 END Initialize;
101 
102 
103 -- Function  	Print_Debug
104 --
105 -- Usage	Used by server program to check the debug flag
106 --
107 
108 FUNCTION Print_Debug RETURN BOOLEAN IS
109 BEGIN
110 
111     return (FA_DEBUG_FLAG = 'YES');
112 
113 END Print_Debug;
114 
115 
116 -- Procedure	Add
117 --
118 -- Usage	Used by server programs to add debug message to
119 --		debug message table
120 --
121 -- Desc		This procedure is oeverloaded.
122 --		There are four datatypes differing in Value parameter:
123 --		   Base :
124 --			Value	VARCHAR2
125 --		   first overloaded procedure :
126 --			Value   NUMBER
127 --		   second overloaded procedure :
128 --			Value	DATE
129 --		   fourth overloaded procedure :
130 --			Value   BOOLEAN
131 --
132 PROCEDURE Add
133 (	fname		in	varchar2,
134 	element		in	varchar2,
135 	value		in	varchar2,
136         p_log_level_rec in      fa_api_types.log_level_rec_type default null
137 ) IS
138 	debug_str	varchar2(225);
139 BEGIN
140 
141     FA_DEBUG_COUNT := FA_DEBUG_COUNT + 1;
142 
143     debug_str := substr(element, 1, 150) || ' has the value of ' ||
144 		 substr(value, 1, 54);
145 
146     g_calling_routine :=  'FA.PLSQL.'||fname;
147     if (g_log_statement_level >= g_log_runtime_level) then
148        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT , g_calling_routine, debug_str);
149     end if;
150 
151     if fa_debug_file = 'YES' then
152        fnd_file.put_line(fnd_file.Log,
153 		    fa_debug_table(fa_debug_count).fname || ': '||
154 		    fa_debug_table(fa_debug_count).data);
155     end if;
156 EXCEPTION
157 when fnd_file.utl_file_error then
158   fa_debug_file := 'NO';
159 END Add;
160 
161 
162 PROCEDURE Add
163 (	fname 		in	varchar2,
164 	element		in	varchar2,
165 	value		in	number,
166         p_log_level_rec in      fa_api_types.log_level_rec_type default null
167 ) IS
168 	debug_str	varchar2(225);
169 BEGIN
170 
171     FA_DEBUG_COUNT := FA_DEBUG_COUNT + 1;
172 
173     debug_str := substr(element, 1, 150) || ' has the value of ' ||
174 		 substr(to_char(value), 1, 54);
175 
176     g_calling_routine :=  'FA.PLSQL.'||fname;
177     if (g_log_statement_level >= g_log_runtime_level) then
178        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT , g_calling_routine, debug_str);
179     end if;
180 
181     if fa_debug_file = 'YES' then
182        fnd_file.put_line(fnd_file.Log,
183 		    fa_debug_table(fa_debug_count).fname || ': '||
184 		    fa_debug_table(fa_debug_count).data);
185     end if;
186 EXCEPTION
187 when fnd_file.utl_file_error then
188   fa_debug_file := 'NO';
189 END Add;
190 
191 
192 PROCEDURE Add
193 (	fname		in	varchar2,
194 	element		in	varchar2,
195 	value		in	date,
196         p_log_level_rec in      fa_api_types.log_level_rec_type default null
197 ) IS
198 	debug_str	varchar2(225);
199 BEGIN
200 
201     FA_DEBUG_COUNT := FA_DEBUG_COUNT + 1;
202 
203     debug_str := substr(element, 1, 150) || ' has the value of ' ||
204 		 to_char(value, 'DD-MM-YYYY HH24:MI:SS');
205 
206     g_calling_routine :=  'FA.PLSQL.'||fname;
207     if (g_log_statement_level >= g_log_runtime_level) then
208        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT , g_calling_routine, debug_str);
209     end if;
210 
211     if fa_debug_file = 'YES' then
212        fnd_file.put_line(fnd_file.Log,
213 		    fa_debug_table(fa_debug_count).fname || ': '||
214 		    fa_debug_table(fa_debug_count).data);
215     end if;
216 
217 EXCEPTION
218 when fnd_file.utl_file_error then
219   fa_debug_file := 'NO';
220 END Add;
221 
222 
223 PROCEDURE Add
224 (	fname		in 	varchar2,
225 	element		in	varchar2,
226 	value		in	boolean,
227         p_log_level_rec in      fa_api_types.log_level_rec_type default null
228 ) IS
229 	debug_str	varchar2(225);
230 	l_value		varchar2(5);
231 BEGIN
232 
233     FA_DEBUG_COUNT := FA_DEBUG_COUNT + 1;
234 
235     if (value) then
236 	l_value := 'TRUE';
237     else
238 	l_value := 'FALSE';
239     end if;
240 
241     debug_str := substr(element, 1, 150) || ' has the value of ' || l_value;
242 
243     g_calling_routine :=  'FA.PLSQL.'||fname;
244     if (g_log_statement_level >= g_log_runtime_level) then
245        FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT , g_calling_routine, debug_str);
246     end if;
247 
248 
249     if fa_debug_file = 'YES' then
250        fnd_file.put_line(fnd_file.Log,
251 		    fa_debug_table(fa_debug_count).fname || ': '||
252 		    fa_debug_table(fa_debug_count).data);
253     end if;
254 EXCEPTION
255 when fnd_file.utl_file_error then
256   fa_debug_file := 'NO';
257 END Add;
258 
259 
260 -- Procedure	Get_Debug_Messages
261 --
262 -- Usage	Used by client program to get debug messages from debug
263 --		table
264 --
265 PROCEDURE Get_Debug_Messages
266 (	d_mesg1	 out nocopy varchar2,
267 	d_mesg2	 out nocopy varchar2,
268 	d_mesg3	 out nocopy varchar2,
269 	d_mesg4	 out nocopy varchar2,
270 	d_mesg5	 out nocopy varchar2,
271 	d_mesg6	 out nocopy varchar2,
272 	d_mesg7	 out nocopy varchar2,
273 	d_mesg8	 out nocopy varchar2,
274 	d_mesg9	 out nocopy varchar2,
275 	d_mesg10 out nocopy varchar2,
276 	d_more_mesgs out nocopy boolean
277 ) IS
278 	l_temp_str	varchar2(255) := NULL;
279 	l_more_mesgs	boolean	:= TRUE;
280 	l_index		number;
281 BEGIN
282     d_mesg1 := NULL;
283     d_mesg2 := NULL;
284     d_mesg3 := NULL;
285     d_mesg4 := NULL;
286     d_mesg5 := NULL;
287     d_mesg6 := NULL;
288     d_mesg7 := NULL;
289     d_mesg8 := NULL;
290     d_mesg9 := NULL;
291     d_mesg10 := NULL;
292     d_more_mesgs := TRUE;
293 
294     --dbms_output.put_line('ENTER - get_debug_messages, index = ' ||
295     --			to_char(FA_DEBUG_INDEX) || ' count = ' ||
296     --			to_char(FA_DEBUG_COUNT));
297 
298     IF (FA_DEBUG_INDEX >= FA_DEBUG_COUNT) THEN
299 	d_more_mesgs := FALSE;
300         RETURN;
301     END IF;
302 
303     WHILE l_more_mesgs LOOP
304 
305 	FA_DEBUG_INDEX := FA_DEBUG_INDEX + 1;
306 
307   	if (FA_DEBUG_INDEX > FA_DEBUG_COUNT) then
308      	    l_more_mesgs := FALSE;
309             EXIT;
310   	else
311    	    l_temp_str := FA_DEBUG_TABLE(FA_DEBUG_INDEX).fname || ': ' ||
312 			  FA_DEBUG_TABLE(FA_DEBUG_INDEX).data;
313 
314      	    l_index := mod(FA_DEBUG_INDEX, 10);
315 
316      	    if (l_index = 1) then
317             	d_mesg1 := l_temp_str;
318      	    elsif (l_index = 2) then
319             	d_mesg2 := l_temp_str;
320      	    elsif (l_index = 3) then
321             	d_mesg3 := l_temp_str;
322      	    elsif (l_index = 4) then
323             	d_mesg4 := l_temp_str;
324      	    elsif (l_index = 5) then
325             	d_mesg5 := l_temp_str;
326 	    elsif (l_index = 6) then
327             	d_mesg6 := l_temp_str;
328 	    elsif (l_index = 7) then
329             	d_mesg7 := l_temp_str;
330      	    elsif (l_index = 8) then
331             	d_mesg8 := l_temp_str;
332 	    elsif (l_index = 9) then
333             	d_mesg9 := l_temp_str;
334             else
335             	d_mesg10 := l_temp_str;
336 		l_more_mesgs := FALSE;
337             end if;
338         end if;
339     END LOOP;
340 
341     if (FA_DEBUG_INDEX >= FA_DEBUG_COUNT) then
342 	d_more_mesgs := FALSE;
343     end if;
344 
345 EXCEPTION
346     WHEN OTHERS THEN
347     	FA_DEBUG_TABLE.DELETE;
348     	FA_DEBUG_COUNT := 0;
349     	FA_DEBUG_INDEX := 0;
350 	d_mesg1 := 'Database Error: ' || SQLERRM;
351 	d_more_mesgs := FALSE;
352 END Get_Debug_Messages;
353 
354 
355 -- Procedure  	Set_Debug_Flag
356 --
357 -- Usage	Used by internal deveoplers to set the debug flag
358 --		to 'YES'
359 --
360 PROCEDURE Set_Debug_Flag
361 (	debug_flag	in	varchar2 := 'YES'
362 ) IS
363 BEGIN
364     FA_DEBUG_FLAG := debug_flag;
365     FA_DEBUG_TABLE.DELETE;
366     FA_DEBUG_COUNT := 0;
367     FA_DEBUG_INDEX := 0;
368 
369     if FA_DEBUG_FLAG = 'NO' then
370 	FA_DEBUG_FILE := 'NO';
371     end if;
372 END Set_Debug_Flag;
373 
374 
375 -- Procedure	Reset_Index
376 --
377 -- Usage	Used by internal developer to move the index
378 --		of debug table
379 --
380 PROCEDURE Reset_Index
381 (	d_index		in number
382 ) IS
383 BEGIN
384     if (d_index is null) then
385 	FA_DEBUG_INDEX := 0;
386     else
387 	FA_DEBUG_INDEX := d_index;
388     end if;
389 END Reset_Index;
390 
391 
392 -- Procedure	Dump_Debug_Messages
393 --
394 -- Usage	Used by internal developers to print all messages
395 --		of debug table
396 --
397 PROCEDURE Dump_Debug_Messages
398 (	target_str	in	varchar2
399 ) IS
400 	t_count	number;
401 BEGIN
402     t_count := FA_DEBUG_TABLE.count;
403     --dbms_output.put_line('Dumping Debug Messages :');
404     --dbms_output.put_line('FA_DEBUG_COUNT = ' || to_char(FA_DEBUG_COUNT));
405     --dbms_output.put_line('FA_DEBUG_INDEX = ' || to_char(FA_DEBUG_INDEX));
406 /*
407     if (target_str is null) then
408 
409 	FOR I IN 1..FA_DEBUG_COUNT LOOP
410 	   dbms_output.put_line( FA_DEBUG_TABLE(I).fname || ': ' ||
411 			         FA_DEBUG_TABLE(I).data);
412 	END LOOP;
413 
414      end if;
415 */
416 EXCEPTION
417     WHEN OTHERS THEN
418 	--dbms_output.put_line('Dump_Debug_Messages : Error - ' ||  SQLERRM);
419 	null;
420 END Dump_Debug_Messages;
421 
422 
423 PROCEDURE Dump_Debug_Messages
424 (       max_mesgs       in      number := NULL) IS
425 
426    l_debug_msg1  varchar2(255);
427    l_debug_msg2  varchar2(255);
428    l_debug_msg3  varchar2(255);
429    l_debug_msg4  varchar2(255);
430    l_debug_msg5  varchar2(255);
431    l_debug_msg6  varchar2(255);
432    l_debug_msg7  varchar2(255);
433    l_debug_msg8  varchar2(255);
434    l_debug_msg9  varchar2(255);
435    l_debug_msg10 varchar2(255);
436    l_more_debug_msgs   boolean;
437 
438 BEGIN
439 
440    fnd_message.set_name('OFA', 'FA_SHARED_DEBUG');
441    fnd_message.set_token('INFO', 'Debug');
442    fnd_msg_pub.add;
443 
444    loop
445 
446       fa_debug_pkg.Get_Debug_Messages
447        (d_mesg1         => l_debug_msg1,
448         d_mesg2         => l_debug_msg2,
449         d_mesg3         => l_debug_msg3,
450         d_mesg4         => l_debug_msg4,
451         d_mesg5         => l_debug_msg5,
452         d_mesg6         => l_debug_msg6,
453         d_mesg7         => l_debug_msg7,
454         d_mesg8         => l_debug_msg8,
455         d_mesg9         => l_debug_msg9,
456         d_mesg10        => l_debug_msg10,
457         d_more_mesgs    => l_more_debug_msgs);
458 
459       fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
460       fnd_message.set_token('MSG1', l_debug_msg1);
461       fnd_msg_pub.add;
462 
463       if l_debug_msg2 is not null then
464          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
465          fnd_message.set_token('MSG1', l_debug_msg2);
466          fnd_msg_pub.add;
467       end if;
468       if l_debug_msg3 is not null then
469          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
470          fnd_message.set_token('MSG1', l_debug_msg3);
471          fnd_msg_pub.add;
472       end if;
473       if l_debug_msg4 is not null then
474          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
475          fnd_message.set_token('MSG1', l_debug_msg4);
476          fnd_msg_pub.add;
477       end if;
478       if l_debug_msg5 is not null then
479          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
480          fnd_message.set_token('MSG1', l_debug_msg5);
481          fnd_msg_pub.add;
482       end if;
483       if l_debug_msg6 is not null then
484          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
485          fnd_message.set_token('MSG1', l_debug_msg6);
486          fnd_msg_pub.add;
487       end if;
488       if l_debug_msg7 is not null then
489          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
490          fnd_message.set_token('MSG1', l_debug_msg7);
491          fnd_msg_pub.add;
492       end if;
493       if l_debug_msg8 is not null then
494          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
495          fnd_message.set_token('MSG1', l_debug_msg8);
496          fnd_msg_pub.add;
497       end if;
498       if l_debug_msg9 is not null then
499          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
500          fnd_message.set_token('MSG1', l_debug_msg9);
501          fnd_msg_pub.add;
502       end if;
503       if l_debug_msg10 is not null then
504          fnd_message.set_name('OFA', 'FA_SRVR_MESSAGE_1');
505          fnd_message.set_token('MSG1', l_debug_msg10);
506          fnd_msg_pub.add;
507       end if;
508 
509       if not l_more_debug_msgs then
510          exit;
511       end if;
512 
513    end loop;
514 
515 EXCEPTION
516   when others then
517     null;
518 
519 END Dump_Debug_messages;
520 
521 -- Procedure Write_Debug_Log
522 --
523 PROCEDURE Write_Debug_Log
524 IS
525     l_debug_str varchar2(255) := NULL;
526 BEGIN
527     if (FA_DEBUG_COUNT > 0) then
528         for i in 1..(FA_DEBUG_COUNT) loop
529             l_debug_str := FA_DEBUG_TABLE(i).fname||':'||
530                            FA_DEBUG_TABLE(i).data;
531             fa_rx_conc_mesg_pkg.log(l_debug_str);
532         end loop;
533     end if;
534 END Write_Debug_Log;
535 
536 
537 END FA_DEBUG_PKG;