1 PACKAGE BODY eam_debug AS
2 /* $Header: EAMDBGJB.pls 120.1 2005/06/30 01:56:40 pkathoti noship $ */
3 /* Copied from pa_DEBUG */
4
5 -- Initialize PROCEDURE
6
7 PROCEDURE initialize IS
8 BEGIN
9 NULL;
10
11 EXCEPTION
12 WHEN OTHERS THEN
13 RAISE;
14 END initialize;
15
16 PROCEDURE enable_debug IS
17 BEGIN
18 debug_flag := TRUE;
19 debug_level:= DEBUG_LEVEL_BASIC;
20 END enable_debug;
21
22 PROCEDURE enable_debug (x_debug_level IN NUMBER) IS
23 BEGIN
24 debug_flag := TRUE;
25 debug_level := x_debug_level;
26 END enable_debug;
27
28 PROCEDURE disable_debug IS
29 BEGIN
30 debug_flag := FALSE;
31 END disable_debug;
32
33 PROCEDURE set_debug_level (x_debug_level IN NUMBER) IS
34 BEGIN
35 debug_level := x_debug_level;
36 END set_debug_level;
37
38 PROCEDURE debug (x_debug_message IN VARCHAR2) IS
39 rest varchar2(32767);
40 BEGIN
41 IF (debug_flag AND x_debug_message IS NOT NULL) THEN
42 IF ( debug_level = DEBUG_LEVEL_TIMING) THEN
43 rest := to_char(sysdate, 'DD-MON-YYYY HH:MI:SS ') || x_debug_message;
44 ELSE
45 rest := x_debug_message;
46 END IF;
47 LOOP
48 IF (rest IS NULL) THEN
49 exit;
50 ELSE
51 number_of_debug_messages := number_of_debug_messages + 1;
52 debug_message(number_of_debug_messages) := substrb(rest,1,255);
53 rest := substrb(rest, 256);
54 END IF; -- IF (rest IS NULL)
55 END LOOP;
56 END IF; -- IF (debug_flag)
57 END debug;
58
59 PROCEDURE debug (x_debug_message IN VARCHAR2, x_debug_level IN NUMBER) IS
60 old_debug_flag BOOLEAN;
61 BEGIN
62 IF ( debug_level >= x_debug_level ) THEN
63 IF ( x_debug_level = DEBUG_LEVEL_EXCEPTION ) THEN
64 old_debug_flag := debug_flag;
65 debug_flag := TRUE;
66 debug(x_debug_message);
67 debug_flag := old_debug_flag;
68 ELSE
69 debug(x_debug_message);
70 END IF;
71 END IF;
72 END debug;
73
74 PROCEDURE get_message(x_message_number IN NUMBER,
75 x_debug_message OUT NOCOPY VARCHAR2) IS
76 BEGIN
77 IF (x_message_number > 0 ) THEN
78 x_debug_message := debug_message(x_message_number);
79 END IF;
80 END get_message;
81
82 FUNCTION no_of_debug_messages RETURN NUMBER IS
83 BEGIN
84 return number_of_debug_messages;
85 END no_of_debug_messages;
86 --------------------------------------------------------------------
87 /* APIs for handling processes, errors, named locks */
88 --------------------------------------------------------------------
89
90 PROCEDURE Set_User_Lock_Mode ( x_Lock_Mode IN NUMBER DEFAULT 6,
91 x_Commit_Mode IN BOOLEAN DEFAULT FALSE,
92 x_TimeOut IN NUMBER DEFAULT 0 )
93 IS
94 BEGIN
95
96 G_LockMode := NVL(x_Lock_Mode,6);
97 G_CommitMode := NVL(x_Commit_Mode,FALSE);
98 G_TimeOut := NVL(x_TimeOut,0);
99
100 END Set_User_Lock_Mode;
101
102
103 ----------------------------------------------------------------
104 /** Acquire_User_Lock : Function to acquire a user lock.
105 x_lock_name : name of the lock.
106 x_lock_mode : Mode of the lock ( Exclusive,..)
107 x_commit_mode : Rls with commit or not
108 Returns : 0 if successful in acquiring lock
109 : < 0 ( -1 to -5) if error in requesting lock (error status)
110 : -99 if unable to allocate unique handle for the lock
111 Ora Errors are not handled
112 **/
113
114
115 FUNCTION Acquire_User_Lock ( x_Lock_Name IN VARCHAR2,
116 x_Lock_Mode IN NUMBER ,
117 x_Commit_Mode IN BOOLEAN,
118 x_TimeOut IN NUMBER )
119 RETURN NUMBER
120 IS
121 lstatus number;
122 lockhndl varchar2(128);
123
124 BEGIN
125
126 /* If Lock Name is NULL then return -99 */
127
128 IF (x_Lock_Name IS NULL ) Then
129 Return -99;
130 END IF;
131
132 /* get lock handle for user lock */
133
134 dbms_lock.allocate_unique(x_lock_name,lockhndl,G_TimeOut);
135
136 IF ( lockhndl IS NOT NULL ) then
137 /* Get the lock, do not release the lock on commit */
138
139 lstatus := dbms_lock.request(lockhndl,
140 NVL(x_lock_mode,G_LockMode),
141 G_TimeOut,
142 NVL(x_commit_mode,G_CommitMode));
143
144 IF ( lstatus = 0 ) then /* Got the lock */
145 Return 0;
146 ELSE
147 Return (-1*lstatus);/* Return the status obtained on request */
148 END IF;
149 ELSE
150 Return -99; /* Failed to allocate lock */
151 END IF;
152
153 END Acquire_User_Lock;
154
155 FUNCTION Acquire_User_Lock ( x_Lock_Name IN VARCHAR2)
156 RETURN NUMBER
157 IS
158 BEGIN
159
160 Return Acquire_User_Lock( x_Lock_Name,G_LockMode,G_CommitMode,G_TimeOut
161 );
162
163 END Acquire_User_Lock;
164
165
166 ------------------------------------------------------------------
167 /** Release_User_Lock : Function to release user lock.
168 x_Lock_Name : The lock name to release
169 Returns :0 - success,
170 :< 0 - Error.
171 Ora Errors are not handled
172 **/
173
174
175 FUNCTION Release_User_Lock ( x_Lock_Name IN VARCHAR2 )
176 RETURN NUMBER
177 IS
178 lstatus NUMBER;
179 lockhndl VARCHAR2(128);
180
181 BEGIN
182
183 /* If Lock Name is NULL then return -99 */
184
185 IF (x_Lock_Name IS NULL ) Then
186 Return -99;
187 END IF;
188
189 /* get lock handle for user lock */
190
191 dbms_lock.allocate_unique(x_lock_name,lockhndl,G_TimeOut);
192
193 IF ( lockhndl IS NOT NULL ) then
194 /* Release the Lock */
195
196 lstatus := dbms_lock.release(lockhndl);
197
198 IF ( lstatus = 0 ) then /* Lock Released */
199 Return 0;
200 ELSE
201 Return (-1*lstatus);/* Return the status obtained on release */
202 END IF;
203 ELSE
204 Return -99; /* Failed to allocate lock */
205 END IF;
206
207 END Release_User_Lock;
208
209 ------------------------------------------------------------------
210 Procedure Set_Process ( x_Process IN VARCHAR2 DEFAULT 'PLSQL',
211 x_Write_File IN VARCHAR2 DEFAULT 'LOG',
212 x_Debug_Mode IN VARCHAR2 DEFAULT 'N' )
213 IS
214
215 BEGIN
216 Select decode(x_Process,'PLSQL','PLSQL','SQL','SQL','REPORT',
217 'REPORT','FORM','FORM','PLSQL'),
218 decode(x_Write_File,'LOG','LOG','OUT','OUT','LOG')
219 Into G_Process, G_WriteFile
220 From dual;
221
222 IF (x_Debug_Mode = 'Y') then
223 Enable_Debug;
224 ELSE
225 Disable_Debug;
226 END IF;
227
228 IF (G_Process = 'PLSQL') then
229 Select decode(G_WriteFile,'LOG',FND_FILE.LOG,FND_FILE.OUTPUT )
230 Into G_WriteFileID
231 From dual;
232 ELSIF (G_Process = 'REPORT') then
233 Enable_Debug; /* If REPORT is used, then need to enable debug */
234 ELSIF (G_Process = 'FORM') then
235 Enable_Debug;
236 number_of_debug_messages := 0;
237 END IF;
238
239 END Set_Process;
240 ---------------------------------------------------------------------
241 Procedure Write_File ( x_Write_File IN VARCHAR2,
242 x_Msg IN VARCHAR2,
243 x_Write_Mode IN NUMBER DEFAULT 0)
244 IS
245 rest varchar2(32767);
246 rest1 varchar2(32767);
247
248 BEGIN
249 /* Write only if mandatory : Write_Mode = 1
250 OR Optional for Debug : Write_Mode = 0 and Debug flag */
251
252 rest := x_msg;
253
254 IF (x_Write_Mode <> 0 OR (x_Write_Mode = 0 AND Debug_Flag )) Then
255 LOOP
256 IF (rest IS NULL) THEN
257 exit;
258 ELSE
259 rest1 := substrb(rest,1,255);
260 rest := substrb(rest, 256);
261 END IF; -- IF (rest IS NULL)
262
263 IF G_Process = 'PLSQL' then
264 IF NVL(x_Write_File,G_WriteFile) = 'OUT' then
265 FND_FILE.PUT(FND_FILE.OUTPUT,rest1);
266 FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
267 ELSIF NVL(x_Write_File,G_WriteFile) = 'LOG' then
268 FND_FILE.PUT(FND_FILE.LOG,rest1);
269 FND_FILE.NEW_LINE(FND_FILE.LOG);
270 ELSE
271 FND_FILE.PUT(G_WriteFileID,rest1);
272 FND_FILE.NEW_LINE(G_WriteFileID);
273 END IF;
274 ELSIF G_Process = 'SQL' then
275 /* DBMS_OUTPUT.PUT_LINE(rest1); */
276 NULL;
277 ELSIF G_Process = 'IGNORE' then
278 NULL;
279 ELSE /* This applies to REPORT and FORM */
280 Debug(rest1);
281 End if;
282 END LOOP;
283 End If;
284
285 EXCEPTION
286
287 WHEN UTL_FILE.INVALID_PATH THEN
288 raise_application_error(-20010,'INVALID PATH exception from UTL_FILE !!'
289 || G_Err_Stack ||' - '||G_Err_Stage);
290
291 WHEN UTL_FILE.INVALID_MODE THEN
292 raise_application_error(-20010,'INVALID MODE exception from UTL_FILE !!'
293 || G_Err_Stack ||' - '||G_Err_Stage);
294
295 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
296 raise_application_error(-20010,'INVALID FILEHANDLE exception from UTL_FILE !!'
297 || G_Err_Stack ||' - '||G_Err_Stage);
298
299 WHEN UTL_FILE.INVALID_OPERATION THEN
300 raise_application_error(-20010,'INVALID OPERATION exception from UTL_FILE !!'
301 || G_Err_Stack ||' - '||G_Err_Stage);
302
303 WHEN UTL_FILE.READ_ERROR THEN
304 raise_application_error(-20010,'READ ERROR exception from UTL_FILE !!'
305 || G_Err_Stack ||' - '||G_Err_Stage);
306
307 WHEN UTL_FILE.WRITE_ERROR THEN
308 raise_application_error(-20010,'WRITE ERROR exception from UTL_FILE !!'
309 || G_Err_Stack ||' - '||G_Err_Stage);
310
311 WHEN UTL_FILE.INTERNAL_ERROR THEN
312 raise_application_error(-20010,'INTERNAL ERROR exception from UTL_FILE !!'
313 || G_Err_Stack ||' - '||G_Err_Stage);
314
315 END Write_File;
316 ---------------------------------------------------------------------
317 Procedure Write_File( x_Msg IN VARCHAR2,
318 x_Write_Mode IN NUMBER DEFAULT 0 )
319 IS
320 BEGIN
321 Write_File( G_WriteFile, x_Msg, x_Write_Mode ) ;
322 END Write_File;
323 ---------------------------------------------------------------------
324 Procedure Write_Log ( x_Module IN VARCHAR2,
325 x_Msg IN VARCHAR2,
326 x_Log_Level IN NUMBER DEFAULT 6 )
327 IS
328 BEGIN
329 IF ( x_Log_Level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
330 FND_LOG.STRING(x_Log_Level,x_Module,x_Msg);
331 END IF;
332 END Write_Log;
333 ----------------------------------------------------------------------
334 Procedure Init_Err_Stack ( x_Stack IN VARCHAR2 )
335 IS
336 BEGIN
337 G_Err_Ind := 1;
338 G_Err_Stack_Tbl(1) := x_Stack;
339 G_Err_Stack := x_Stack;
340
341 END Init_Err_Stack;
342 -----------------------------------------------------------------
343 Procedure Set_Err_Stack ( x_Stack IN VARCHAR2 )
344 IS
345 BEGIN
346 G_Err_Stack := G_Err_Stack || '->'||x_Stack;
347 END Set_Err_Stack;
348 -----------------------------------------------------------------
349 Procedure Reset_Err_Stack
350 IS
351 BEGIN
352 G_err_stack := substr(G_err_stack, 1, instr(G_err_stack,'->',-1,1)-1) ;
353 END Reset_Err_Stack;
354 ------------------------------------------------------------------
355
356 PROCEDURE raise_error(x_Msg_Num IN NUMBER ,
357 x_Msg IN VARCHAR2 ,
358 x_TokenName1 IN VARCHAR2 ,
359 x_Token1 IN VARCHAR2 ,
360 x_TokenName2 IN VARCHAR2 ,
361 x_Token2 IN VARCHAR2 ,
362 x_TokenName3 IN VARCHAR2 ,
363 x_Token3 IN VARCHAR2 )
364 IS
365
366 BEGIN
367 fnd_message.set_name('PA', x_msg);
368 fnd_message.set_token(x_TokenName1, x_Token1);
369 fnd_message.set_token(x_TokenName2, x_Token2);
370 fnd_message.set_token(x_TokenName3, x_Token3);
371
372 raise_application_error(x_Msg_Num,fnd_message.get);
373
374 END raise_error;
375
376 -------------------------------------------------------------------
377 PROCEDURE raise_error(x_Msg_Num IN NUMBER ,
378 x_Msg IN VARCHAR2 ,
379 x_TokenName1 IN VARCHAR2 ,
380 x_Token1 IN VARCHAR2 ,
381 x_TokenName2 IN VARCHAR2 ,
382 x_Token2 IN VARCHAR2 )
383 IS
384
385 BEGIN
386 fnd_message.set_name('PA', x_msg);
387 fnd_message.set_token(x_TokenName1, x_Token1);
388 fnd_message.set_token(x_TokenName2, x_Token2);
389
390 raise_application_error(x_Msg_Num,fnd_message.get);
391
392 END raise_error;
393
394 -------------------------------------------------------------------
395 PROCEDURE raise_error(x_Msg_Num IN NUMBER ,
396 x_Msg IN VARCHAR2 ,
397 x_TokenName1 IN VARCHAR2 ,
398 x_Token1 IN VARCHAR2 )
399 IS
400
401 BEGIN
402 fnd_message.set_name('PA', x_msg);
403 fnd_message.set_token(x_TokenName1, x_Token1);
404
405 raise_application_error(x_Msg_Num,fnd_message.get);
406
407 END raise_error;
408
409 -------------------------------------------------------------------
410 PROCEDURE raise_error(x_Msg_Num IN NUMBER ,
411 x_Msg IN VARCHAR2 )
412 IS
413
414 BEGIN
415 fnd_message.set_name('PA', x_msg);
416
417 raise_application_error(x_Msg_Num,fnd_message.get);
418
419 END raise_error;
420
421 -------------------------------------------------------------------
422
423
424 --Name: Log_Message
425 --Type: Procedure
426 --Description: This procedure writes sysdate date and time, the
427 -- current procedure name and the passed message
431 --
428 -- to the log file.
429 --
430 --Called subprograms: write_file
432 --History:
433 -- 29-NOV-00 jwhite Cloned
434 --
435 -- 07-DEC-00 jwhite Added the p_msg_options IN parameter
436 -- to give the developer more
437 -- options for the log message
438 -- format:
439 --
440 -- 1. PLAIN: prints the p_message
441 -- as is. This is the default.
442 -- 2. TIME: prints HH24:MI:SS, space,
443 -- function name,:, p_message.
444 -- 3. DATETIME: prints YYYY/MM/DD HH24:MI:SS,
445 -- space, function name,:, p_message.
446 --
447 -- PLEASE NOTE: If you place a pa_debug.log_message with either
448 -- the TIME or DATETIME p_msg_option just
449 -- before a SQL%ROWCOUNT,
450 -- the SQL%ROWCOUNT will return 1.
451 --
452 -- 11-DEC-00 jwhite For log_message, modified code to only
453 -- print function name for log file.
454 --
455
456 PROCEDURE Log_Message( p_message IN VARCHAR2
457 , p_write_mode IN NUMBER DEFAULT 0
458 , p_msg_options IN VARCHAR2 DEFAULT 'PLAIN'
459 , p_write_file IN VARCHAR2 DEFAULT 'LOG'
460 )
461 IS
462
463 l_function VARCHAR2(50) := NULL;
464
465 BEGIN
466
467 IF (G_Function_Stack.exists(G_Function_Counter))
468 THEN
469 l_function := G_Function_Stack(G_Function_Counter);
470 END IF;
471
472
473 IF (p_write_file = 'LOG')
474 THEN
475 -- Print Function Name
476 IF (p_msg_options = 'PLAIN')
477 THEN
478 eam_debug.write_file(p_write_file, g_space ||
479 l_function || ': ' ||p_message, p_write_mode);
480
481 ELSIF (p_msg_options = 'TIME')
482 THEN
483 eam_debug.write_file(p_write_file,
484 to_char(sysdate,'HH24:MI:SS') || g_space ||
485 l_function || ': ' ||p_message, p_write_mode);
486 ELSE
487 -- Treat as DATETIME, including illegal values.
488 eam_debug.write_file(p_write_file,
489 to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') || g_space ||
490 l_function || ': ' ||p_message, p_write_mode);
491 END IF;
492
493 ELSE
494 -- Do Not Print Function Name
495 IF (p_msg_options = 'PLAIN')
496 THEN
497 eam_debug.write_file(p_write_file, g_space ||p_message, p_write_mode);
498
499 ELSIF (p_msg_options = 'TIME')
500 THEN
501 eam_debug.write_file(p_write_file,
502 to_char(sysdate,'HH24:MI:SS') || g_space ||p_message, p_write_mode);
503 ELSE
504 -- Treat as DATETIME, including illegal values.
505 eam_debug.write_file(p_write_file,
506 to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') || g_space ||p_message, p_write_mode);
507 END IF;
508 END IF;
509
510 EXCEPTION
511
512 WHEN OTHERS
513 THEN
514 raise;
515
516 END log_message;
517
518 -------------------------------------------------------------------
519 --Name: Set_Curr_Function
520 --Type: Procedure
521 --Description: This procedure conditionally calls either
522 -- the init_err_stack and set_process procedures
523 -- or the set_err_stack procedure. See the aforementioned
524 -- procedures for more information about their
525 -- functionality.
526 --
527 -- With respect to the set_err_stack procedure, this
528 -- procedure extends the functionality of the
529 -- set_err_stack procedure by nesting subroutine messages
530 -- within the overall program flow.
531 --
532 --
533 --Called subprograms: eam_debug.init_err_stack
534 -- eam_debug.set_process
535 -- eam_debug.set_err_stack
536 --
537 --History:
538 -- 29-NOV-00 jwhite Cloned
539 --
540
541 PROCEDURE Set_Curr_Function(p_function IN VARCHAR2
542 , p_process IN VARCHAR2 DEFAULT 'PLSQL'
543 , p_write_file IN VARCHAR2 DEFAULT 'LOG'
544 , p_debug_mode IN VARCHAR2 DEFAULT 'N'
545 )
546 IS
547 BEGIN
548
549 G_Function_Counter := G_Function_Counter + 1;
550 G_Function_Stack(G_Function_Counter) := p_function;
551 G_Space := G_Space || ' ';
552
553 IF ( G_Function_Counter = 1)
554 THEN
555 eam_debug.init_err_stack(p_function);
556 eam_debug.set_process (p_process, p_write_file, p_debug_mode);
557 ELSE
558 eam_debug.set_err_stack(p_function);
559 END IF;
560
561 END Set_Curr_Function;
562
563 -------------------------------------------------------------------
564 --Name: Reset_Curr_Function
565 --Type: Procedure
566 --Description: This procedure removes the current procedure
567 -- or function name from the error stack. This
568 -- procedure also adjusts the global for
569 -- indentation, accordingly.
570 --
574 -- 29-NOV-00 jwhite Cloned
571 --Called subprograms: eam_debug.reset_err_stack
572 --
573 --History:
575 --
576
577 PROCEDURE Reset_Curr_Function
578 IS
579 BEGIN
580
581 G_Function_Stack.delete(G_Function_Counter);
582 G_Function_Counter := G_Function_Counter -1;
583 G_Space := substr(G_Space,1,length(G_Space)-2);
584 eam_debug.reset_err_stack;
585
586 END Reset_Curr_Function;
587
588
589
590 END eam_debug;