DBA Data[Home] [Help]

PACKAGE BODY: APPS.CLN_DEBUG_PUB

Source


1 PACKAGE BODY CLN_DEBUG_PUB AS
2 /* $Header: CLNDBGB.pls 115.9 2003/06/30 14:37:30 kkram noship $ */
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('cln-' || to_char(sysdate,'dd-mon-yyyy') || '-' || lpad(cln_debug_s.nextval,6,'0'),1,22) || '.dbg'
12           into G_FILE
13           from dual;
14           G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'a');
15        end if;
16        rtn_val := G_DIR || '/' || g_file;
17     elsif P_MODE = 'CONC' then
18        G_DEBUG_MODE := 'CONC';
19        rtn_val := null;
20     else
21        G_DEBUG_MODE := 'TABLE';
22        rtn_val := null;
23     end if;
24     debug_on;
25     --SetDebugLevelFromProfile;
26     return(rtn_val);
27 Exception when others then
28     G_DEBUG_MODE := 'TABLE';
29     rtn_val := null;
30     return(rtn_val);
31 End;
32 
33 
34 PROCEDURE Initialize
35 IS
36 BEGIN
37     G_Debug_tbl.DELETE;
38     G_Debug_count := 0;
39     G_Debug_index := 0;
40 END Initialize;
41 
42 
43 Procedure Debug_ON
44 IS
45 Begin
46   G_DEBUG := FND_API.G_TRUE;
47 End Debug_On;
48 
49 
50 Procedure Debug_OFF
51 IS
52 Begin
53   G_DEBUG := FND_API.G_FALSE;
54 End Debug_Off;
55 
56 
57 Function ISDebugOn
58 Return Boolean IS
59 Begin
60   if G_DEBUG = FND_API.G_TRUE then
61      RETURN(TRUE);
62   else
63      RETURN(FALSE);
64   end if;
65 End ISDebugOn;
66 
67 
68 FUNCTION GetDebugCount
69 RETURN NUMBER
70 IS
71 BEGIN
72     RETURN G_Debug_Count;
73 END GetDebugCount;
74 
75 
76 --  PROCEDURE   Add
77 --
78 --  Usage       Used to add Debugs to the global message table.
79 
80 PROCEDURE Add(p_debug_msg in Varchar2, p_debug_level in Number)
81 IS
82         l_fname VARCHAR2(80);
83         l_debug_msg     VARCHAR2(2000);
84         l_g_miss_char   VARCHAR2(12) := FND_API.G_MISS_CHAR;
85         l_replace       VARCHAR2(12) := ' G_MISS_CHAR';
86         l_file          VARCHAR2(255);
87 
88 BEGIN
89 
90   IF G_DEBUG_LEVEL IS NULL THEN
91          SetDebugLevelFromProfile;
92   END IF;
93   -- kkram -- not sure about the following block. To check later...
94   /*if not ISDebugOn then
95          if nvl(fnd_profile.value('CONC_REQUEST_ID'),0) <> 0 then
96             l_fname := set_debug_mode('CONC');
97          else
98             l_fname := set_debug_mode('FILE');
99          end if;
100   end if;*/
101   if (p_debug_level >= G_Debug_Level) then
102     --if (ISDebugOn) then
103       if p_debug_msg is not null then
104           if G_DEBUG_MODE = 'TABLE' then
105              --  Increment Debug count
106              G_Debug_count := G_debug_count + 1;
107              --  Write Debug.
108              G_Debug_tbl(G_debug_count) := substr(p_debug_msg,1,G_DEBUG_LEN);
109 
110           elsif G_DEBUG_MODE = 'CONC' then /* Concurrent program mode.
111                         Write to concurrent pgm output file and debug log file */
112            l_debug_msg := substr(replace(to_char(sysdate,'dd-mon-yyyy hh24:mi:ss')||':'||p_debug_level||': '||p_debug_msg,l_g_miss_char,l_replace),1,2000);
113              FND_FILE.put_line(FND_FILE.LOG, l_debug_msg);
114            if G_FILE is not null then
115                 utl_file.put_line(G_FILE_PTR, p_debug_msg);
116                 utl_file.fflush(G_FILE_PTR);
117            end if;
118           else -- debug mode is FILE
119              l_debug_msg := substr(replace(to_char(sysdate,'dd-mon-yyyy hh24:mi:ss')||':'||p_debug_level||': '||p_debug_msg,l_g_miss_char,l_replace),1,2000);
120              IF G_FILE is null THEN
121                  l_file :=cln_debug_pub.Set_Debug_Mode('FILE');
122              END IF;
123              utl_file.put_line(G_FILE_PTR, l_debug_msg);
124              utl_file.fflush(G_FILE_PTR);
125           end if;
126       end if; -- p_debug_msg is not null
127     --end if; -- debug on
128   end if;-- debug level is big enough
129 Exception
130  WHEN OTHERS then
131      if g_debug_mode = 'TABLE' then
132        G_DEBUG_COUNT := G_DEBUG_COUNT - 1;
133      end if;
134      debug_off; -- Internal exception turn the debug off
135 END add; -- Add
136 
137 
138 Procedure GetFirst(Debug_msg OUT NOCOPY Varchar2)
139 IS
140 BEGIN
141   resetindex;
142  if G_DEBUG_COUNT <> 0 then
143     debug_msg := G_DEbug_tbl(1);
144     g_debug_index := 1;
145  else
146    debug_msg := null;
147  end if;
148 Exception when others then
149    debug_msg := null;
150 END GetFirst;
151 
152 
153 Procedure GetNext(debug_msg OUT NOCOPY varchar2) is
154 Begin
155    if g_debug_count > g_debug_index then
156       g_debug_index := g_debug_index + 1;
157        debug_msg := G_Debug_tbl(g_debug_index);
158    else
159      debug_msg := null;
160    end if;
161 Exception when others then
162    debug_msg := null;
163 End GetNext;
164 
165 
166 Function ISLastMsg
167 return number is
168 Begin
169   if g_debug_count <= g_debug_index then
170      return(1);
171   else
172      return(0);
173   end if;
174 End ISLastMsg;
175 
176 
177 Procedure GetNextBuffer(p_debug_msg in OUT NOCOPY varchar2) is
178 msg_str varchar2(500);
179 i number;
180 x_buffer_len number := 0;
181 x_msg_len   number := 0;
182 x_prev_index number;
183 x_msg_count number := 1;
184 begin
185 p_debug_msg := '';
186  if G_DEBUG_COUNT > 0 and g_debug_index < g_debug_count then
187     loop
188     x_prev_index := g_debug_index;
189       x_msg_len := length(G_DEbug_tbl(g_debug_index+1));
190       if (x_buffer_len + x_msg_len) < 2000 and x_msg_count <40 then
191           g_debug_index := g_debug_index + 1;
192           x_msg_count := x_msg_count + 1;
193           p_debug_msg := p_debug_msg || fnd_global.local_chr(10) || G_DEBUG_TBL(g_debug_index);
194           x_buffer_len := x_buffer_len + x_msg_len;
195       else
196         exit;
197       end if;
198       if (g_debug_index >= g_debug_count) or x_prev_index = g_debug_index then
199          exit;
200       end if;
201     end loop;
202  end if;
203 end;
204 
205 
206 Procedure ResetIndex is
207 begin
208   g_debug_index := 0;
209 end;
210 
211 
212 Procedure SetDebugLevelFromProfile
213 IS
214 Begin
215   G_Debug_Level   := to_number(nvl(fnd_profile.value('CLN_DEBUG_LEVEL'), '0'));
216 Exception
217   WHEN OTHERS THEN
218     G_DEBUG_LEVEL := 5;
219 End SetDebugLevelFromProfile;
220 
221 Procedure SetDebugLevel(p_debug_level in number)
222 IS
223 Begin
224   G_DEBUG_LEVEL := p_debug_level;
225 Exception
226   WHEN OTHERS THEN
227     G_DEBUG_LEVEL := 5;
228 End SetDebugLevel;
229 
230 END CLN_DEBUG_PUB;