DBA Data[Home] [Help]

PACKAGE BODY: APPS.WF_LOG_PKG

Source


1 package body WF_LOG_PKG as
2 /* $Header: WFLOGPKB.pls 120.3.12000000.2 2007/07/03 21:53:24 vshanmug ship $ */
3 
4 LEVEL_UNEXPECTED CONSTANT NUMBER  := 6;
5 LEVEL_ERROR      CONSTANT NUMBER  := 5;
6 LEVEL_EXCEPTION  CONSTANT NUMBER  := 4;
7 LEVEL_EVENT      CONSTANT NUMBER  := 3;
8 LEVEL_PROCEDURE  CONSTANT NUMBER  := 2;
9 LEVEL_STATEMENT  CONSTANT NUMBER  := 1;
10 
11 ------------------------------------------------------------------------------
12 /*
13 ** Init - Initialise the Logging global variables to do standalone testing.
14 **        This will do the same work as wf_log_pkg.wf_debug_flag.
15 **        (This API to be used by WF Dev only)
16 */
17 procedure Init (
18    LOG_ENABLED  in binary_integer,
19    LOG_FILENAME in varchar2,
20    LOG_LEVEL    in number,
21    LOG_MODULE   in varchar2,
22    FND_USER_ID  in number,
23    FND_RESP_ID  in number,
24    FND_APPL_ID  in number
25 )
26 is
27   l_user_id number;
28   l_resp_id number;
29   l_appl_id number;
30 begin
31 
32    if (FND_USER_ID is NULL) then
33       l_user_id := 0;
34    else
35       l_user_id := FND_USER_ID;
36    end if;
37 
38    if (FND_RESP_ID is NULL) then
39       l_resp_id := -1;
40    else
41       l_resp_id := FND_RESP_ID;
42    end if;
43 
44    if (FND_APPL_ID is NULL) then
45       l_appl_id := -1;
46    else
47       l_appl_id := FND_APPL_ID;
48    end if;
49 
50    FND_GLOBAL.Apps_Initialize(l_user_id, l_resp_id, l_appl_id);
51 
52    if (log_enabled = 1) then
53       FND_PROFILE.Put('AFLOG_ENABLED', 'Y');
54    end if;
55 
56    if (log_filename is NOT NULL) then
57       FND_PROFILE.Put('AFLOG_FILENAME', log_filename);
58    end if;
59 
60    if (log_level is NOT NULL) then
61       FND_PROFILE.Put('AFLOG_LEVEL', log_level);
62    end if;
63 
64    if (log_module is NOT NULL) then
65       FND_PROFILE.Put('AFLOG_MODULE', log_module);
66    end if;
67 
68    FND_LOG_REPOSITORY.Init();
69 
70 exception
71    when others then
72       wf_core.context('WF_LOG_PKG', 'Init');
73       raise;
74 end Init;
75 ------------------------------------------------------------------------------
76 
77 /*
78 ** set_level - Described in Spec
79 **
80 */
81 procedure SET_LEVEL(
82   LOG_LEVEL in number
83 )
84 is
85 
86 begin
87    if (log_level is NOT NULL) then
88       FND_PROFILE.Put('AFLOG_LEVEL', log_level);
89 
90       -- Seems that the change of profile doesn't automatically
91       -- populate the FND_LOG log level.
92       FND_LOG_REPOSITORY.Init();
93 
94    end if;
95 end SET_LEVEL;
96 
97 
98 
99 /*
100 ** String - Described in Spec
101 **
102 */
103 procedure String(
104   LOG_LEVEL	in number,
105   MODULE	in varchar2,
106   MESSAGE	in varchar2
107 )
108 is
109 begin
110 
111   if( LOG_LEVEL >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
112    if (FND_LOG.Test(log_level, module)) then
113       FND_LOG.String(log_level, module, message);
114    end if;
115   end if;
116 
117 exception
118   when others then
119     null;
120 end String;
121 
122 ------------------------------------------------------------------------------
123 /*
124 **  Test - Check if logging is enabled for the given level and module.
125 **         Better to call FND_LOG.Test directly in order to avoid overhead.
126 */
127 function Test(
128    LOG_LEVEL in number,
129    MODULE    in varchar2
130 )
131 return boolean
132 is
133 begin
134 
135   return FND_LOG.Test(log_level, module);
136 
137 end Test;
138 
139 /*
140 ** MESSAGE
141 **  Wrapper to FND_LOG.MESSAGE
142 **  Writes a message to the log file if this level and module is enabled
143 **  This requires that the message was set previously with
144 **  WF_LOG_PKG.SET_NAME, WF_LOG_PKG.SET_TOKEN, etc.
145 **  The message is popped off the message dictionary stack, if POP_MESSAGE
146 **  is TRUE.  Pass FALSE for POP_MESSAGE if the message will also be
147 **  displayed to the user later.  If POP_MESSAGE isn't passed, the
148 **  message will not be popped off the stack, so it must be displayed
149 **  or explicitly cleared later on.
150 */
151 procedure MESSAGE (
152    LOG_LEVEL   in number,
153    MODULE      in varchar2,
154    POP_MESSAGE in boolean)
155 is
156 begin
157   if( LOG_LEVEL >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
158    FND_LOG.MESSAGE(LOG_LEVEL,
159 		   MODULE,
160 		   POP_MESSAGE);
161  end if;
162 end MESSAGE;
163 
164 /*
165 ** SET_NAME
166 **   Wrapper to FND_MESSAGE.SET_NAME
167 **   Sets the message name
168 */
169 procedure SET_NAME(
170    APPLICATION in varchar2,
171    NAME        in varchar2
172 )
173 is
174 begin
175    FND_MESSAGE.SET_NAME(APPLICATION,
176 			NAME);
177 end;
178 
179 /*
180 ** SET_TOKEN
181 **   Wrapper to FND_MESSAGE.SET_TOKEN
182 **   Defines a message token with a value
183 */
184 procedure SET_TOKEN (
185    TOKEN     in varchar2,
186    VALUE     in varchar2,
187    TRANSLATE in boolean
188 )
189 is
190 begin
191    FND_MESSAGE.SET_TOKEN(TOKEN,
192 			 VALUE,
193 			 TRANSLATE);
194 end;
195 
196 ------------------------------------------------------------------------------
197 /*
198 ** String2 - Described in Spec
199 **
200 */
201 procedure String2(
202   LOG_LEVEL     in number,
203   MODULE        in varchar2,
204   MESSAGE       in varchar2,
205   STARTS        in boolean
206 )
207 is
208    l_elapsed_time varchar2(40);
209    l_log          varchar2(70);
210    l_end_time     number;
211    l_start_time   number;
212    l_idx          number;
213 begin
214    -- using 2^20 as the size of the hash table
215    l_idx := dbms_utility.get_hash_value(module, 1, 1048576);
216 
217    if (starts) then
218      wf_log_pkg.g_start_times(l_idx) := dbms_utility.get_time();
219      l_log := ' [Start time '||to_char(wf_log_pkg.g_start_times(l_idx))||']';
220    else
221      l_end_time := dbms_utility.get_time();
222      l_start_time := wf_log_pkg.g_start_times(l_idx);
223 
224      -- Retaining the start time may help printing incremental
225      -- elapsed time... Scope for improvement later.
226      wf_log_pkg.g_start_times.delete(l_idx);
227 
228      l_elapsed_time := trunc(((l_end_time-l_start_time)/100), 2);
229      l_log := ' [End time '||to_char(l_end_time)||']';
230      l_log := l_log||' [Time taken - '||to_char(l_elapsed_time)||' secs]';
231    end if;
232 
233   if( LOG_LEVEL >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
234    if (FND_LOG.Test(log_level, module)) then
235       FND_LOG.String(log_level, module, message||l_log);
236    end if;
237   end if;
238 
239 exception
240   when others then
241     null;
242 end String2;
243 ------------------------------------------------------------------------------
244 
245 end WF_LOG_PKG;