DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_DEBUG_PUB

Source


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