DBA Data[Home] [Help]

PACKAGE BODY: APPS.BIS_DEBUG_PUB

Source


1 PACKAGE BODY BIS_DEBUG_PUB AS
2 /* $Header: BISPDBGB.pls 120.1 2005/07/02 04:22:51 appldev ship $ */
3 
4 
5 
6 Function Set_Debug_Mode(P_Mode in varchar2) Return Varchar2 IS
7    rtn_val   Varchar2(100);
8 Begin
9     if P_MODE = 'FILE' then
10        G_DEBUG_MODE := 'FILE';
11 
12        if G_DIR is null then
13           select value
14 	    INTO G_DIR
15 	    from v$PARAMETER where name = 'utl_file_dir';
16 	  if instr(G_DIR,',') > 0 then
17 	     G_DIR := substr(G_DIR,1,instr(G_DIR,',')-1);
18 	  end if;
19        END IF;
20 
21        if G_FILE is null then
22           select substr('l'|| substr(to_char(sysdate,'MI'),1,1)
23                  || lpad(BIS_debug_s.nextval,6,'0'),1,8) || '.BIS'
24           into G_FILE
25           from dual;
26           G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'w');
27        end if;
28        rtn_val := G_DIR || '/' || g_file;
29     else
30        G_DEBUG_MODE := 'TABLE';
31        rtn_val := null;
32     end if;
33     return(rtn_val);
34 Exception when others then
35     G_DEBUG_MODE := 'TABLE';
36     rtn_val := null;
37     return(rtn_val);
38 End;
39 PROCEDURE Initialize
40 IS
41 BEGIN
42 
43 G_Debug_tbl.DELETE;
44 G_Debug_count := 0;
45 G_Debug_index := 0;
46 
47 END Initialize;
48 
49 Procedure Debug_ON
50 IS
51 Begin
52   BIS_DEBUG_PUB.G_DEBUG := FND_API.G_TRUE;
53 End Debug_On;
54 
55 Procedure Debug_OFF
56 IS
57 Begin
58   BIS_DEBUG_PUB.G_DEBUG := FND_API.G_FALSE;
59 End Debug_Off;
60 
61 Function ISDebugOn
62 Return Boolean IS
63 Begin
64   if BIS_DEBUG_PUB.G_DEBUG = FND_API.G_TRUE then
65      RETURN(TRUE);
66   else
67      RETURN(FALSE);
68   end if;
69 End ISDebugOn;
70 --  FUNCTION    Count_Debug
71 --
72 --  Usage       Used by API callers and developers to find the count
73 --              of Debugs in the  message list.
74 --  Desc        Returns the value of G_Debug_count
75 --
76 --  Parameters  None
77 --
78 --  Return      NUMBER
79 
80 FUNCTION CountDebug         RETURN NUMBER
81 IS
82 BEGIN
83 
84     RETURN G_Debug_Count;
85 
86 END CountDebug;
87 
88 --  PROCEDURE   Add
89 --
90 --  Usage       Used to add Debugs to the global message table.
91 --
92 --
93 
94 PROCEDURE Add(debug_msg in Varchar2, debug_level in Number default 1)
95 IS
96 BEGIN
97   if (G_Debug_Level >= debug_level) then
98     if (ISDebugOn) then
99       if debug_msg is not null then
100 	 if G_DEBUG_MODE = 'TABLE' then
101 	     --  Increment Debug count
102 	     G_Debug_count := G_debug_count + 1;
103 	     --  Write Debug.
104 	     G_Debug_tbl(G_debug_count) := substr(debug_msg,1,G_DEBUG_LEN);
105 	  else -- debug mode
106 	     utl_file.put_line(G_FILE_PTR, debug_msg);
107 	     utl_file.fflush(G_FILE_PTR);
108 	  end if;
109       end if; -- debug_msg is not null
110     end if; -- debug on
111   end if;-- debug level is big enough
112 Exception
113  WHEN OTHERS then
114      if g_debug_mode = 'TABLE' then
115       G_DEBUG_COUNT := G_DEBUG_COUNT - 1;
116      end if;
117       debug_off; -- Internal exception turn the debug off
118 END add; -- Add
119 
120 Procedure GetFirst(Debug_msg out Varchar2)
121 IS
122 BEGIN
123   resetindex;
124  if G_DEBUG_COUNT <> 0 then
125     debug_msg := G_DEbug_tbl(1);
126     g_debug_index := 1;
127  else
128    debug_msg := null;
129  end if;
130 Exception when others then
131    debug_msg := null;
132 END GetFirst;
133 
134 Procedure GetNext(debug_msg out varchar2) is
135 Begin
136    if g_debug_count > g_debug_index then
137       g_debug_index := g_debug_index + 1;
138        debug_msg := G_Debug_tbl(g_debug_index);
139    else
140      debug_msg := null;
141    end if;
142 Exception when others then
143    debug_msg := null;
144 End GetNext;
145 
146 Function ISLastMsg
147 return number is
148 Begin
149   if g_debug_count <= g_debug_index then
150      return(1);
151   else
152      return(0);
153   end if;
154 End ISLastMsg;
155 
156 PROCEDURE    DumpDebug
157 IS
158 i number := 0;
159 BEGIN
160 dbms_output.enable(100000);
161    for i in 1..g_debug_count loop
162 --      dbms_output.put_line('Number : '|| to_char(i) || ' :: ' ||
163 --                              G_debug_tbl(i));
164       NULL;
165    end loop;
166 END DumpDebug;
167 
168 Procedure GetNextBuffer(p_debug_msg in out varchar2) is
169 msg_str varchar2(2000);
170 i number;
171 x_buffer_len number := 0;
172 x_msg_len   number := 0;
173 x_prev_index number;
174 x_msg_count number := 1;
175 begin
176 p_debug_msg := '';
177 
178  if G_DEBUG_COUNT > 0 and g_debug_index < g_debug_count then
179     loop
180     x_prev_index := g_debug_index;
181     x_msg_len := length(G_DEbug_tbl(g_debug_index+1));
182 
183       if (x_buffer_len + x_msg_len) < 1900 and x_msg_count <40 then
184           g_debug_index := g_debug_index + 1;
185           x_msg_count := x_msg_count + 1;
186 --          p_debug_msg := p_debug_msg || chr(10) || G_DEBUG_TBL(g_debug_index);
187           p_debug_msg := p_debug_msg || fnd_global.local_chr(10) || G_DEBUG_TBL(g_debug_index);
188           p_debug_msg := p_debug_msg || ' ' || G_DEBUG_TBL(g_debug_index);
189           x_buffer_len := x_buffer_len + x_msg_len;
190       else
191         exit;
192       end if;
193       if (g_debug_index >= g_debug_count) or x_prev_index = g_debug_index then
194          exit;
195       end if;
196     end loop;
197  end if;
198 end;
199 
200 Procedure ResetIndex is
201 begin
202   g_debug_index := 0;
203 end;
204 
205 Procedure SetDebugLevel(p_debug_level in number)
206 IS
207 Begin
208   BIS_DEBUG_PUB.G_DEBUG_LEVEL := p_debug_level;
209 End SetDebugLevel;
210 
211 END BIS_DEBUG_PUB;