1 PACKAGE BODY OKC_DEBUG AS
2 /* $Header: OKCDBUGB.pls 120.0 2005/05/25 22:52:14 appldev noship $ */
3
4 l_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
5
6 -- g_user_id Number := OKC_API.G_MISS_NUM;
7 g_indent_str Varchar2(4000) := Null;
8 g_proc Varchar2(80);
9
10 TYPE proc_tbl IS TABLE OF VARCHAR2(80) INDEX BY BINARY_INTEGER;
11
12 g_proc_tbl proc_tbl;
13 g_index Number := 0;
14 G_MAX_INDENT_STR_LEN CONSTANT NUMBER(4) := 1880;
15
16 Procedure Set_Indentation(p_proc_name Varchar2) IS
17 --
18 -- This procedure sets the indentation global string for the debug
19 -- messages. This global string will be prefixed before the actual
20 -- messages is printed. Also sets global procedure name which gets
21 -- printed along with the mesasges. This procedure should be called
22 -- at the beginning of each procedure and the procedure name should
23 -- be passed as the parameter.
24 --
25 Begin
26 --
27 -- set trace on/off flag depending on the profile option
28 -- if trace off, do not call indentation
29 -- the flag will be set whenever the indent string is null
30 -- bug 2170106, jkodiyan
31 --
32 if g_indent_str is null then
33 if FND_PROFILE.VALUE('AFLOG_ENABLED') = 'Y' then
34 Set_trace_on;
35 else
36 Set_trace_off;
37 end if;
38 end if;
39
40 if g_set_trace_off then
41 return;
42 end if;
43
44 --
45 -- Set the global procedure name
46 --
47 g_proc := p_proc_name;
48 --
49 -- Increase the indent string by 2 spaces.
50 --
51 g_indent_str := g_indent_str || ' ';
52 -- See comments above for bug 2216341
53 If Length(g_indent_str) > G_MAX_INDENT_STR_LEN Then
54 g_indent_str := ' ';
55 End If;
56 --
57 -- Store the procedure name in the stack. This step is important
58 -- otherwise we will loose this information once we are back
59 -- to the calling procedure from the called procedure.
60 --
61 g_index := g_index + 1;
62 g_proc_tbl(g_index) := p_proc_name;
63 End Set_Indentation;
64
65 Procedure Reset_Indentation IS
66 --
67 -- Sets the global procedure name to null. Also reduces the global
68 -- indentation string by 2 characters. This procedure must be
69 -- called before all the exit points within the procedure. The exit
70 -- point include the last statement in the procedure, all the return
71 -- statements and the outermost exceptions (unless there is return
72 -- within inner exceptions). This procedure must be called in
73 -- conjunction with Set_Indentation. That means in one is called,
74 -- the second one must also be called or none should be called.
75 --
76 Begin
77 --
78 -- do nothing if the trace is set to off
79 -- bug 2170106, jkodiyan
80 --
81 if g_set_trace_off then
82 return;
83 end if;
84
85 --
86 -- Reset the indent string by 2 space.
87 --
88 g_indent_str := Substr(g_indent_str, 1, Length(g_indent_str) - 2);
89 --
90 -- Drop the current called procedure name from the stack since
91 -- we just exited.
92 --
93 g_proc_tbl.delete(g_index);
94 --
95 -- Get the parent calling procedure name from the stack.
96 --
97 g_index := g_index - 1;
98 If g_index <= 0 Then
99 g_index := 0;
100 -- Reset the proc name otherwise it prints the last proc name
101 -- if the caller didn't make call to set_indentation.
102 g_proc := Null;
103 else
104 g_proc := g_proc_tbl(g_index);
105 End If;
106 End Reset_Indentation;
107
108 Procedure Set_Connection_Context Is
109 --
110 -- This procedure makes sure that we are in the same session in
111 -- order to use any globals. Unfortunately we do not have any
112 -- fnd_global.session_id like fnd_global.user_id, so we have to
113 -- use context to cache it.
114 --
115 l_session_id Varchar2(30);
116 l_user_id Number;
117 l_resp_id Number;
118 l_resp_appl_id Number;
119 l_log_enable_value Varchar2(30);
120 Begin
121
122 l_session_id := Sys_Context('USERENV', 'SESSIONID');
123
124 If (g_session_id = OKC_API.G_MISS_CHAR) Or
125 (g_session_id <> l_session_id) Then
126 g_session_id := l_session_id;
127 --
128 /* -- Now if we are in new session, we need to call the
129 -- fnd_global.apps_initialize once again so that the
130 -- AOL Logging profiles are set correctly.
131 --
132 l_user_id := Fnd_Global.User_Id;
133 l_resp_id := Fnd_Global.Resp_Id;
134 l_resp_appl_id := Fnd_Global.Resp_Appl_Id;
135
136 Fnd_Global.Apps_Initialize(user_id => l_user_id,
137 resp_id => l_resp_id,
138 resp_appl_id => l_resp_appl_id);
139 */
140
141 g_profile_log_level := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
142
143 End If;
144
145
146 /* If (g_user_id = OKC_API.G_MISS_NUM) Or
147 (g_user_id <> fnd_global.user_id) Then
148 g_user_id := fnd_global.user_id;
149 End If; */
150
151 End Set_Connection_Context;
152
153
154
155 PROCEDURE Log(p_msg IN VARCHAR2,
156 p_level IN NUMBER,
157 p_module IN VARCHAR2) IS
158 Begin
159 --
160 -- First thing, set the connection context
161 --
162 Set_Connection_Context;
163 --
164 -- Make sure that the current logging level is set at least as high
165 -- as in profile option.
166 --
167 IF g_set_trace_off = TRUE Then
168 return;
169 END IF;
170 If (p_level >= g_profile_log_level) Then
171 --
172 -- Also logging should be enabled for the current module.
173 --
174 If Fnd_Log.Test(p_level, p_module) Then
175 If instr(p_msg, OKC_API.G_MISS_CHAR) > 0 then
176 Fnd_Log.String(p_level, p_module, g_indent_str || g_proc || ' : ' ||Replace(p_msg,OKC_API.G_MISS_CHAR,'?'));
177 Else
178 Fnd_Log.String(p_level, p_module, g_indent_str || g_proc || ' : ' ||p_msg);
179 End if;
180 End If;
181 End If;
182 End Log;
183
184 Procedure Set_trace_off IS
185 Begin
186 g_set_trace_off := TRUE;
187
188 End Set_trace_off;
189
190 Procedure Set_trace_on IS
191 Begin
192 g_set_trace_off := FALSE;
193 End Set_trace_on;
194
195 END OKC_DEBUG;