DBA Data[Home] [Help]

PACKAGE BODY: APPS.ASO_DEBUG_PUB

Source


1 PACKAGE BODY ASO_DEBUG_PUB as
2 /* $Header: asoidbgb.pls 120.2 2009/10/29 14:59:26 rassharm ship $ */
3 -- Start of Comments
4 -- Package name     : ASO_DEBUG_PUB
5 -- Purpose          :
6 -- History          :
7 -- NOTE             :
8 -- End of Comments
9 
10 Function Set_Debug_Mode(P_Mode in varchar2) Return Varchar2 IS
11 rtn_val   Varchar2(100);
12 l_dbgfile_number number;
13 Begin
14 
15 
16     if P_MODE = 'FILE' then
17 
18        G_DEBUG_MODE := 'FILE';
19        OE_DEBUG_PUB.G_DEBUG_MODE := 'FILE';
20        if G_FILE is null then
21 	  --IF (ASO_DEBUG_PUB.G_FILE is NULL OR ASO_DEBUG_PUB.G_FILE <> 'ASO'||FND_GLOBAL.USER_NAME||'.dbg') Then
22           select aso_debug_file_s.nextval
23           into l_dbgfile_number
24           from dual;
25 
26 		G_FILE := substr('l'|| substr(to_char(sysdate,'MI'),1,1)
27 				|| lpad(l_dbgfile_number,6,'0'),1,8)
28 				|| fnd_global.user_name
29 				|| '.dbg';
30 
31           G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'a');
32 	oe_debug_pub.G_FILE_PTR := G_FILE_PTR;
33        end if;
34        rtn_val := G_DIR || '/' || g_file;
35     elsif P_MODE = 'CONC' then
36        --G_DEBUG_MODE := 'CONC';
37        rtn_val := null;
38     else
39        --G_DEBUG_MODE := 'TABLE';
40        rtn_val := null;
41     end if;
42 
43     aso_debug_pub.setdebuglevel(G_Debug_Level);
44     aso_debug_pub.debug_on;
45 
46     return(rtn_val);
47  Exception when others then
48     G_DEBUG_MODE := 'FILE';
49     --rtn_val := null;
50     return(rtn_val);
51 End;
52 
53 
54 PROCEDURE Initialize
55 IS
56 BEGIN
57 
58 G_Debug_tbl.DELETE;
59 G_Debug_count := 0;
60 G_Debug_index := 0;
61 
62 OE_DEBUG_PUB.G_Debug_tbl.DELETE;
63 OE_DEBUG_PUB.G_Debug_count := 0;
64 OE_DEBUG_PUB.G_Debug_index := 0;
65 OE_DEBUG_PUB.G_DIR  := ASO_DEBUG_PUB.G_DIR;
66 OE_DEBUG_PUB.G_FILE  := ASO_DEBUG_PUB.G_FILE;
67 
68 END Initialize;
69 
70 
71 Procedure Debug_ON
72 IS
73 Begin
74   ASO_DEBUG_PUB.G_DEBUG := FND_API.G_TRUE;
75   -- bug 9040436
76   if  OE_DEBUG_PUB.G_DEBUG= FND_API.G_FALSE then
77     OE_DEBUG_PUB.G_DEBUG := FND_API.G_TRUE;
78   end if;
79 End Debug_On;
80 
81 
82 Procedure Debug_OFF
83 IS
84 Begin
85   ASO_DEBUG_PUB.G_DEBUG := FND_API.G_FALSE;
86   OE_DEBUG_PUB.G_DEBUG := FND_API.G_FALSE;
87 End Debug_Off;
88 
89 
90 Function ISDebugOn
91 Return Boolean IS
92 Begin
93   if ASO_DEBUG_PUB.G_DEBUG = FND_API.G_TRUE then
94      RETURN(TRUE);
95   else
96      RETURN(FALSE);
97   end if;
98 End ISDebugOn;
99 
100 
101 --  FUNCTION    Count_Debug
102 --
103 --  Usage       Used by API callers and developers to find the count
104 --              of Debugs in the  message list.
105 --  Desc        Returns the value of G_Debug_count
106 --
107 --  Parameters  None
108 --
109 --  Return      NUMBER
110 
111 FUNCTION CountDebug         RETURN NUMBER
112 IS
113 BEGIN
114 
115     RETURN G_Debug_Count;
116 
117 END CountDebug;
118 
119 
120 --  PROCEDURE   Add
121 --
122 --  Usage       Used to add Debugs to the global message table.
123 
124 PROCEDURE Add(debug_msg in Varchar2, debug_level in Number := 1, print_date in varchar2 := 'N' )
125 IS
126 	l_fname	VARCHAR2(80);
127 	l_date  varchar2(80);
128 
129 BEGIN
130 
131 
132    if ASO_DEBUG_PUB.G_FILE = 'OFF' then
133       return;
134    end if;
135 
136    if ASO_DEBUG_PUB.G_FILE is null then
137        if nvl(fnd_profile.value('ASO_ENABLE_DEBUG'),'N') = 'Y' then
138            aso_debug_pub.SetDebugLevel(10);
139            l_fname := set_debug_mode('FILE');
140            -- I could not test this, But this is the problem. This should be set after
141            -- set_debug_mode call, other G_FILE will be null
142            OE_DEBUG_PUB.G_DIR  := ASO_DEBUG_PUB.G_DIR;
143            OE_DEBUG_PUB.G_FILE  := ASO_DEBUG_PUB.G_FILE;
144            utl_file.put_line(G_FILE_PTR, 'Hello Sir, U have Opened a New Session');
145        else
146            ASO_DEBUG_PUB.G_FILE := 'OFF';
147            return;
148        end if;
149    end if;
150 
151 
152    if G_Debug_Level > 0 then
153       /*
154       if NOT ISDebugOn then
155 	     if nvl(fnd_profile.value('CONC_REQUEST_ID'),0) <> 0 then
156 	         l_fname := set_debug_mode('CONC');
157 	     else
158 	         l_fname := set_debug_mode('FILE');
159 	     end if;
160       end if;
161       */ -- Commented OUT for bug 1990541.
162 
163       if (G_Debug_Level >= debug_level) then
164           if (ISDebugOn) then
165               if debug_msg is not null then
166 	             if G_DEBUG_MODE = 'TABLE' then
167 	                 -- Increment Debug count
168 	                 G_Debug_count := G_debug_count + 1;
169 	                 -- Write Debug.
170 	                 G_Debug_tbl(G_debug_count) := substr(debug_msg,1,G_DEBUG_LEN);
171 	             elsif G_DEBUG_MODE = 'CONC' then /* Concurrent program mode.
172 			                                       Write to the table, concurrent pgm output file and
173                                                       also to the debug log file */
174 	                 G_Debug_count := G_debug_count + 1;
175 	                 G_Debug_tbl(G_debug_count) := substr(debug_msg,1,G_DEBUG_LEN);
176 	                 FND_FILE.put_line(FND_FILE.LOG, debug_msg);
177                       if G_FILE is not null then
178 	                     utl_file.put_line(G_FILE_PTR, debug_msg);
179 	                     utl_file.fflush(G_FILE_PTR);
180                       end if;
181 	             else -- debug mode
182 		            if print_date = 'Y' then
183 	                     --utl_file.put_line(G_FILE_PTR, debug_msg  ||'  ' || to_char( sysdate, 'DD-MON-YYYY HH:MI:SS' )  );
184 	                     utl_file.put_line(G_FILE_PTR, to_char( sysdate,'DD-MON-YYYY HH:MI:SS') || ' ASO ' || debug_msg );
185 	                     utl_file.fflush(G_FILE_PTR);
186 		            else
187 	                     --utl_file.put_line(G_FILE_PTR, debug_msg);
188 	                     utl_file.put_line(G_FILE_PTR, 'ASO ' || debug_msg );
189 	                     utl_file.fflush(G_FILE_PTR);
190 		            end if;
191 	             end if;
192               end if; -- debug_msg is not null
193           end if; -- debug on
194       end if;-- debug level is big enough
195    end if;
196 
197    EXCEPTION
198         WHEN OTHERS then
199             if g_debug_mode IN ('TABLE','CONC') then
200                 G_DEBUG_COUNT := G_DEBUG_COUNT - 1;
201             end if;
202             debug_off; -- Internal exception turn the debug off
203 
204 END add;
205 
206 
207 Procedure GetFirst(Debug_msg OUT NOCOPY /* file.sql.39 change */  Varchar2)
208 IS
209 BEGIN
210   resetindex;
211  if G_DEBUG_COUNT <> 0 then
212     debug_msg := G_DEbug_tbl(1);
213     g_debug_index := 1;
214  else
215    debug_msg := null;
216  end if;
217 Exception when others then
218    debug_msg := null;
219 END GetFirst;
220 
221 
222 Procedure GetNext(debug_msg OUT NOCOPY /* file.sql.39 change */  varchar2) is
223 Begin
224    if g_debug_count > g_debug_index then
225       g_debug_index := g_debug_index + 1;
226        debug_msg := G_Debug_tbl(g_debug_index);
227    else
228      debug_msg := null;
229    end if;
230 Exception when others then
231    debug_msg := null;
232 End GetNext;
233 
234 
235 Function ISLastMsg
236 return number is
237 Begin
238   if g_debug_count <= g_debug_index then
239      return(1);
240   else
241      return(0);
242   end if;
243 End ISLastMsg;
244 
245 
246 PROCEDURE    DumpDebug
247 IS
248 i number := 0;
249 BEGIN
250 --dbms_output.enable(100000);
251    for i in 1..g_debug_count loop
252       --dbms_output.put_line('Number : '|| to_char(i) || ' :: ' ||
253                               --G_debug_tbl(i));
254 	null;
255    end loop;
256 END DumpDebug;
257 
258 
259 Procedure GetNextBuffer(p_debug_msg IN OUT NOCOPY /* file.sql.39 change */  varchar2) is
260 msg_str varchar2(500);
261 i number;
262 x_buffer_len number := 0;
263 x_msg_len   number := 0;
264 x_prev_index number;
265 x_msg_count number := 1;
266 begin
267 p_debug_msg := '';
268  if G_DEBUG_COUNT > 0 and g_debug_index < g_debug_count then
269     loop
270     x_prev_index := g_debug_index;
271       x_msg_len := length(G_DEbug_tbl(g_debug_index+1));
272       if (x_buffer_len + x_msg_len) < 2000 and x_msg_count <40 then
273           g_debug_index := g_debug_index + 1;
274           x_msg_count := x_msg_count + 1;
275           p_debug_msg := p_debug_msg || fnd_global.local_chr(10) || G_DEBUG_TBL(g_debug_index);
276           x_buffer_len := x_buffer_len + x_msg_len;
277       else
278         exit;
279       end if;
280       if (g_debug_index >= g_debug_count) or x_prev_index = g_debug_index then
281          exit;
282       end if;
283     end loop;
284  end if;
285 end;
286 
287 
288 Procedure ResetIndex is
289 begin
290   g_debug_index := 0;
291 end;
292 
293 
294 Procedure SetDebugLevel(p_debug_level in number)
295 IS
296 Begin
297   ASO_DEBUG_PUB.G_DEBUG_LEVEL := p_debug_level;
298   OE_DEBUG_PUB.G_DEBUG_LEVEL := p_debug_level;
299 End SetDebugLevel;
300 
301 procedure disable_debug_pvt is
302 begin
303    ASO_DEBUG_PUB.Debug_off;
304    ASO_DEBUG_PUB.G_FILE := null;
305    OE_DEBUG_PUB.Debug_off;
306    OE_DEBUG_PUB.G_FILE := null;
307    If utl_file.is_Open(ASO_DEBUG_PUB.G_FILE_PTR) Then
308       utl_file.fclose(ASO_DEBUG_PUB.G_FILE_PTR);
309    End If;
310 exception
311   When Others Then
312    null;
313 end;
314 
315 END ASO_DEBUG_PUB;