1 PACKAGE BODY ASN_DEBUG AS
2 /* $Header: RCVDBUGB.pls 120.0.12010000.3 2008/12/25 01:03:29 vthevark ship $ */
3
4 g_product_code constant varchar2(5) := 'p'||'o'||'.'; -- gscc hack
5
6 /*===========================================================================
7
8 PROCEDURE NAME: PUT_LINE()
9
10 ===========================================================================*/
11
12 PROCEDURE PUT_LINE (v_line in varchar2,v_level in varchar2, v_inv_debug_level in NUMBER) IS /* lcm changes */
13
14 --x_TRACE_ENABLE_FLAG VARCHAR2(1) := 'N';
15 /* FPJ WMS.
16 * Insert into fnd_log_messages for online mode.
17 */
18 l_processing_mode rcv_transactions_interface.processing_mode_code%type ;
19 l_api_name CONSTANT VARCHAR2(40) := 'PUT_LINE';
20 p_module VARCHAR2(255);
21 p_procedure VARCHAR2(20);
22 p_label VARCHAR2(20);
23
24 BEGIN
25 -- uncomment out the line below if you want to run the preprocessor in
26 -- sqlplus
27
28 -- dbms_output.put_line(v_line);
29
30 if ( g_debugging_enabled = 'Y') then
31 get_calling_module(p_module,p_procedure,p_label);
32 -- lcm changes
33 debug_msg_ex(v_line,p_module,p_procedure,p_label,v_level);
34 if (g_inv_debug_enabled = 1) then
35 inv_trx_util_pub.trace(v_line, p_module || '.' || p_procedure, v_inv_debug_level);
36 end if;
37 end if;
38 END PUT_LINE;
39
40 PROCEDURE get_calling_module(p_module OUT NOCOPY VARCHAR2,
41 p_procedure OUT NOCOPY VARCHAR2,
42 p_label OUT NOCOPY VARCHAR2,
43 p_stack_depth IN NUMBER) IS
44 /* p_stack_depth is the rewind depth. for example
45 p_stack_depth = 2 --> calling procedure name
46 p_stack_depth = 1 --> asn_debug.put_line
47 p_stack_depth = 0 --> get_calling_procedure
48 you can override the rewind depth as needed
49 */
50 stk VARCHAR2(2000);
51 len NUMBER;
52 p1 NUMBER;
53 p2 NUMBER;
54 t VARCHAR2(2000);
55 r VARCHAR2(2000);
56 s VARCHAR2(2000);
57 rtn VARCHAR2(1);
58 BEGIN
59 stk:=DBMS_UTILITY.format_call_stack;
60 len:=LENGTH(stk);
61 rtn:=SUBSTRB(stk,-1); --get the return character
62 p1:=INSTRB(stk,rtn,1,p_stack_depth+3)+1;
63 p2:=INSTRB(stk,rtn,1,p_stack_depth+4);
64 t:=SUBSTRB(stk,p1,p2-p1); --isolated stack line
65 t:=trim(substrb(t,instrb(t,' '))); --get rid of object address
66 r:=substrb(t,0,instrb(t,' ')-1); --isolate line number
67 s:=trim(substrb(t,instrb(t,' '))); --isolate caller
68 p1:=INSTRB(s,'.',1,1)+1;
69 s:=SUBSTRB(s,p1); --isolate calling procedure
70 p_label:=substrb(r,0,20);
71 p_procedure:=substrb(s,0,20);
72 p_module:=substrb(s,0,255);
73 END get_calling_module;
74
75 FUNCTION get_debugging_enabled return boolean is
76
77 v_value VARCHAR2(128);
78
79 BEGIN
80
81 IF (g_debugging_enabled = 'Y') THEN
82 RETURN TRUE;
83 ELSE
84 RETURN FALSE;
85 END IF;
86
87 end get_debugging_enabled;
88
89 /* set the current module name that you see in the log table */
90 PROCEDURE set_module_name( module in varchar2) is
91 v_module varchar2(255);
92 BEGIN
93 v_module := trim(module);
94 if (substr(v_module,0,3)=g_product_code) then --if explicit set then override default
95 g_current_module := substr(v_module,0,255);
96 elsif (module is not null) then
97 if (lower(substr(v_module,-2,2))='.c') then --call from lpc file
98 v_module := substr(g_product_code||'src.rvtp.'||substr(v_module,0,length(v_module)-2),0,255);
99 else --call from plsql
100 v_module := substr(g_product_code||'plsql.'||v_module,0,255);
101 end if;
102 g_current_module := v_module;
103 end if;
104 END set_module_name;
105
106 /* print stack will print out the current procedure calling stack */
107 PROCEDURE print_stack is
108 BEGIN
109 debug_msg('Current Calling Stack = '||g_procedure_stack);
110 debug_msg(DBMS_UTILITY.FORMAT_CALL_STACK);
111 END;
112
113 /* start procedure adds procedure name to the simulated procedure stack */
114 /* g_procedure_stack is a string that keeps a list of all the stacks */
115 /* this works because each procedure name is sure to have exactly 20 */
116 /* characters so that the substr(g_procedure_stack,60,20) gives you the */
117 /* name of the third procedure on the stack. Note that */
118 /* substr(g_procedure_stack,0,20) is level zero which equals '?' or */
119 /* the unknown procedure. */
120 PROCEDURE start_procedure( procedure_name in varchar2) is
121 BEGIN
122 g_current_procedure := rpad(upper(nvl(substrb(procedure_name,0,20),'?')),20,' ');
123 debug_msg(RPAD('v--------Procedure Started',37,'-')||'v',FND_LOG.LEVEL_PROCEDURE,'begin');
124 g_level := g_level+1;
125 g_procedure_stack := g_procedure_stack||g_current_procedure;
126 EXCEPTION
127 WHEN OTHERS THEN
128 null;
129 END start_procedure;
130
131 /* stop procedure acts like a pop on the stack. If the procedure name */
132 /* equals the name that is currently being used then we can pop the */
133 /* topmost element off and we're done. However, if the name does not */
134 /* equal the topmost element then we need to undo the stack all the way*/
135 /* back to that element - this results in Implicit Procedure Exits */
136 /* which are generally caused by unexpected errors when the procedure */
137 /* is exited abnormally. In the very weird situation where we get a */
138 /* stop procedure for a procedure name we do not recognize, we do not */
139 /* do anything other than mention it was an unknown procedure name */
140 /* note the use of instr to search the string in reverse - this is */
141 /* necessary in the case of recursion and stuff */
142 /* the pop_this_procedure is a flag to indicate not to pop off the */
143 /* current procedure. Useful for the pro*C commands that do not have */
144 /* an explicit procedure termination */
145 PROCEDURE stop_procedure( procedure_name in varchar2, pop_this_procedure in boolean) is
146 l_temp_name VARCHAR2(20);
147 l_temp_level NUMBER;
148 BEGIN
149 l_temp_name := rpad(upper(nvl(substrb(procedure_name,0,20),'?')),20,' ');
150 IF (g_current_procedure <> l_temp_name) THEN -- we need to jump back on the stack
151 l_temp_level := (INSTRB(g_procedure_stack,l_temp_name)-1)/20;
152 WHILE (g_level > l_temp_level) LOOP -- to pop off the procedure that didn't get exited
153 g_level := g_level - 1;
154 debug_msg(RPAD('^--------Implicit Procedure Exit',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end_implicit');
155 g_current_procedure := SUBSTRB(g_procedure_stack,g_level*20+1,20);
156 END LOOP;
157 END IF;
158 if (pop_this_procedure = TRUE) then
159 IF (g_current_procedure = l_temp_name) then -- now pop off the called procedure
160 g_level := g_level-1;
161 debug_msg(RPAD('^--------Procedure Ended',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end');
162 IF (g_level<0) THEN -- shouldn't happen unless you call stop_procedure('?'), but just to be safe
163 g_level := 0;
164 g_current_procedure := RPAD('?',20,' ');
165 ELSE -- the normal situation, reset the current procedure to the previous procedure on the stack
166 g_current_procedure := SUBSTRB(g_procedure_stack,g_level*20+1,20);
167 END IF;
168 ELSE -- the name given wasn't anywhere on the stack
169 debug_msg(RPAD('^--------Unknown Procedure ['||procedure_name||'] Ended',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end_unknown');
170 END IF;
171 end if;
172 g_procedure_stack := substrb(g_procedure_stack,1,(g_level+1)*20);
173 EXCEPTION
174 WHEN OTHERS THEN
175 null;
176 END stop_procedure;
177
178 PROCEDURE debug_msg(line in varchar2, level in varchar2, label in varchar2) is
179 -- If you do not specify a level then it will default to log level: Statement
180 -- If you do not specify a module then it will use the last module specified
181 -- if there is no last module specified then it Will default to module name: RCV
182 v_level NUMBER;
183 BEGIN
184 if ( g_debugging_enabled = 'Y' ) then
185 v_level := nvl(level,FND_LOG.LEVEL_STATEMENT);
186
187 -- GSCC HACK: need redundant v_level >= FND_CUR_LEVEL check do not remove
188 if( v_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL AND FND_LOG.TEST(v_level, G_CURRENT_MODULE )) then
189 FND_LOG.STRING(v_level,
190 substrb(G_CURRENT_MODULE||'.'
191 ||trim(nvl(G_CURRENT_PROCEDURE,'?'))||'.'
192 ||trim(nvl(label,'-1'))
193 ,0,255)
194 ,RPAD(' ',2*g_level)||line);
195 FND_FILE.PUT_LINE(FND_FILE.LOG , '[' || to_char(sysdate,'DD-MON-YY HH24:MI:SS') || '] '||rpad(SUBSTR(g_current_module,INSTRB(g_current_module,'.',-1)+1,20),20,' ')||' '||LPAD(nvl(label,'-1'),5,' ')||':'||RPAD(' ',2*g_level+1)||line);
196 end if;
197
198 end if;
199 EXCEPTION
200 WHEN OTHERS THEN
201 null;
202
203 END debug_msg;
204
205 /* debug_msg_ex is an extended version of the debug_msg procedure which is */
206 /* specifically designed to facilitate the pro*C calls*/
207 PROCEDURE debug_msg_ex(message in varchar2, module in varchar2, procedure_name in varchar2, line_num in number,level in varchar2) is
208 v_procedure_name VARCHAR2(20);
209 begin
210 if ( g_debugging_enabled = 'Y') then
211
212 if (procedure_name is not null) then
213 v_procedure_name := rpad(upper(nvl(substrb(procedure_name,instrb(procedure_name,'/',-1)+1,20),'?')),20,' ');
214 if (v_procedure_name<>g_current_procedure) then
215 if (instr(g_procedure_stack,v_procedure_name)>0) then
216 stop_procedure(v_procedure_name,false);
217 if (module is not null) then
218 set_module_name(substrb(module,instrb(module,'/',-1)+1));
219 end if;
220 else
221 if (module is not null) then
222 set_module_name(substrb(module,instrb(module,'/',-1)+1));
223 end if;
224 start_procedure(v_procedure_name);
225 end if;
226 end if;
227 end if;
228
229 debug_msg(message,level,line_num);
230 end if;
231 EXCEPTION
232 WHEN OTHERS THEN
233 null;
234 end debug_msg_ex;
235
236 END ASN_DEBUG;