1 PACKAGE BODY DOM_LOG as
2 /*$Header: DOMULOGB.pls 120.0 2006/07/14 22:32:35 mkimizuk noship $*/
3
4 --------------------------------------------
5 -- This is Database Session Language. --
6 --------------------------------------------
7 G_SESSION_LANG CONSTANT VARCHAR2(99) := USERENV('LANG');
8
9 --------------------------------------------
10 -- This is the UI language. --
11 --------------------------------------------
12 G_LANGUAGE_CODE VARCHAR2(3);
13
14 ----------------------------------------------------------------------------
15 -- Debug Profile option used to write Error_Handler.Write_Debug --
16 -- Profile option name = INV_DEBUG_TRACE ; --
17 -- User Profile Option Name = INV: Debug Trace --
18 -- Values: 1 (True) ; 0 (False) --
19 -- NOTE: This better than MRP_DEBUG which is used at many places. --
20 ----------------------------------------------------------------------------
21 -- Not Used
22 -- G_DEBUG CONSTANT VARCHAR2(10) := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
23
24 -- Must be '0' when this pkg is shipped
25 G_DEV_DEBUG CONSTANT VARCHAR2(10) := '0' ;
26
27
28 -----------------------------------------------------------------------
29 -- These are the Constants to generate a New Line Character. --
30 -----------------------------------------------------------------------
31 G_CARRIAGE_RETURN VARCHAR2(1) := FND_GLOBAL.LOCAL_CHR(13);
32 G_LINE_FEED VARCHAR2(1) := FND_GLOBAL.LOCAL_CHR(10);
33 -- Following prints ^M characters in the log file.
34 G_NEWLINE VARCHAR2(2) := G_LINE_FEED;
35
36
37 ---------------------------------------------------------------
38 -- API Return Status . --
39 ---------------------------------------------------------------
40 G_RET_STS_SUCCESS CONSTANT VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
41 G_RET_STS_WARNING CONSTANT VARCHAR2(1) := 'W';
42 G_RET_STS_ERROR CONSTANT VARCHAR2(1) := FND_API.G_RET_STS_ERROR;
43 G_RET_STS_UNEXP_ERROR CONSTANT VARCHAR2(1) := FND_API.G_RET_STS_UNEXP_ERROR;
44
45 ---------------------------------------------------------------
46 -- Used for Error Reporting. --
47 ---------------------------------------------------------------
48 G_ERROR_TABLE_NAME VARCHAR2(30) ;
49 G_ERROR_ENTITY_CODE VARCHAR2(30) ;
50 G_OUTPUT_DIR VARCHAR2(512) ;
51 G_ERROR_FILE_NAME VARCHAR2(400) ;
52 G_BO_IDENTIFIER VARCHAR2(30) := 'DOM_API';
53
54
55 ---------------------------------------------------------------
56 -- Introduced for 11.5.10, so that Java Conc Program can --
57 -- continue writing to the same Error Log File. --
58 ---------------------------------------------------------------
59 G_ERRFILE_PATH_AND_NAME VARCHAR2(10000);
60
61
62 ----------------------------------------------------------
63 -- Write to Concurrent Log --
64 ----------------------------------------------------------
65 PROCEDURE Developer_Debug (p_msg IN VARCHAR2) IS
66 BEGIN
67
68 FND_FILE.put_line(FND_FILE.LOG, p_msg);
69
70
71 EXCEPTION
72 WHEN OTHERS THEN
73 FND_FILE.put_line(FND_FILE.LOG, 'Developer_Debug LOGGING SQL ERROR => '|| SUBSTRB(SQLERRM, 1,240));
74
75 END Developer_Debug ;
76
77
78
79 --
80 -- Writes the message to the log file for the specified
81 -- level and module
82 -- if logging is enabled for this level and module
83 --
84 PROCEDURE LOG_STR(PKG_NAME IN VARCHAR2,
85 API_NAME IN VARCHAR2,
86 LABEL IN VARCHAR2 := NULL ,
87 MESSAGE IN VARCHAR2)
88 IS
89 l_module VARCHAR2(400) ;
90
91 BEGIN
92
93 IF (CHECK_LOG_LEVEL)
94 THEN
95 l_module := DOM_LOG_PREFIX || PKG_NAME || '.' || API_NAME ;
96
97 IF LABEL IS NOT NULL THEN
98 l_module := l_module || '.' || LABEL ;
99 END IF ;
100
101 IF ( DOM_LOG_LEVEL >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
102 FND_LOG.STRING(DOM_LOG_LEVEL,
103 l_module,
104 MESSAGE );
105
106 END IF ;
107
108
109 END IF ;
110
111
112 IF (TO_NUMBER(G_DEV_DEBUG) > 0) THEN
113 l_module := DOM_LOG_PREFIX || PKG_NAME || '.' || API_NAME ;
114
115 IF LABEL IS NOT NULL THEN
116 l_module := l_module || '.' || LABEL ;
117 END IF ;
118
119 Developer_Debug(l_module
120 || '['||TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS')||'] '
121 || MESSAGE
122 );
123
124 END IF ;
125
126 END LOG_STR ;
127
128
129 --
130 -- Tests whether logging is enabled for this level and module,
131 -- to avoid the performance penalty of building long debug
132 -- message strings unnecessarily.
133 --
134 FUNCTION TEST(PKG_NAME IN VARCHAR2,
135 API_NAME IN VARCHAR2)
136 RETURN BOOLEAN
137 IS
138
139 BEGIN
140
141 -- Call FND_LOG.TEST to check
142 -- whether logging is enabled for this level and module,
143 --
144 -- FND_LOG:
145 -- FUNCTION TEST(LOG_LEVEL IN NUMBER, MODULE IN VARCHAR2)
146 -- RETURN BOOLEAN;
147 --
148 RETURN FND_LOG.TEST(DOM_LOG_LEVEL, DOM_LOG_PREFIX || PKG_NAME || '.' || API_NAME ) ;
149
150 END TEST ;
151
152
153 --
154 -- Tests whether DOM logging is enabled for this level
155 --
156 FUNCTION CHECK_LOG_LEVEL
157 RETURN BOOLEAN
158 IS
159 BEGIN
160
161
162
163 IF (TO_NUMBER(G_DEV_DEBUG) > 0) THEN
164 return TRUE ;
165 ELSIF ( DOM_LOG_LEVEL >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
166 return TRUE ;
167 ELSE
168 return FALSE ;
169 END IF ;
170
171 END CHECK_LOG_LEVEL;
172
173
174
175 /*****************************************************************************
176 -- the following methods should not be used in DOM for now
177
178 -----------------------------------------------------------------
179 -- Write Debug statements to Log using Error Handler procedure --
180 -----------------------------------------------------------------
181 PROCEDURE Write_Debug (p_msg IN VARCHAR2) IS
182
183 BEGIN
184
185 -- NOTE: No need to check for profile now, as Error_Handler checks
186 -- for Error_Handler.Get_Debug = 'Y' before writing to Debug Log.
187 -- If Profile set to TRUE --
188 -- IF (G_DEBUG = '1') THEN
189 -- Error_Handler.Write_Debug('['||TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS')||'] '|| p_msg);
190 -- END IF;
191 Error_Handler.Write_Debug('['||TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS')||'] '|| p_msg);
192
193 EXCEPTION
194 WHEN OTHERS THEN
195 FND_FILE.put_line(FND_FILE.LOG, 'Write_Debug LOGGING ERROR => '|| SUBSTRB(SQLERRM, 1,240) );
196
197 END Write_Debug ;
198
199
200 ----------------------------------------------------------
201 -- Internal procedure to open debug session. --
202 ----------------------------------------------------------
203 PROCEDURE open_debug_session_internal IS
204
205 CURSOR c_get_utl_file_dir IS
206 SELECT VALUE
207 FROM V$PARAMETER
208 WHERE NAME = 'utl_file_dir';
209
210 --local variables
211 l_log_output_dir VARCHAR2(512);
212 l_log_return_status VARCHAR2(99);
213 l_errbuff VARCHAR2(999);
214 BEGIN
215
216 Error_Handler.initialize();
217 Error_Handler.set_bo_identifier(G_BO_IDENTIFIER);
218
219 ---------------------------------------------------------------------------------
220 -- Commented on 12/17/2003 (PPEDDAMA). Open_Debug_Session should set the value
221 -- appropriately, so that when the Debug Session is successfully opened :
222 -- will return Error_Handler.Get_Debug = 'Y', else Error_Handler.Get_Debug = 'N'
223 ---------------------------------------------------------------------------------
224 -- Error_Handler.Set_Debug('Y');
225
226 OPEN c_get_utl_file_dir;
227 FETCH c_get_utl_file_dir INTO l_log_output_dir;
228 --developer_debug('UTL_FILE_DIR : '||l_log_output_dir);
229 IF c_get_utl_file_dir%FOUND THEN
230 ------------------------------------------------------
231 -- Trim to get only the first directory in the list --
232 ------------------------------------------------------
233 IF INSTR(l_log_output_dir,',') <> 0 THEN
234 l_log_output_dir := SUBSTR(l_log_output_dir, 1, INSTR(l_log_output_dir, ',') - 1);
235 --developer_debug('Log Output Dir : '||l_log_output_dir);
236 END IF;
237
238
239 IF G_OUTPUT_DIR IS NOT NULL
240 THEN
241 l_log_output_dir := G_OUTPUT_DIR ;
242 END IF ;
243
244
245
246 IF G_ERROR_FILE_NAME IS NULL
247 THEN
248 G_ERROR_FILE_NAME := G_BO_IDENTIFIER ||'_'
249 -- || G_ERROR_TABLE_NAME||'_'
250 || to_char(sysdate, 'DDMONYYYY_HH24MISS')||'.err';
251 END IF ;
252
253 --developer_debug('Trying to open the Error File => '||G_ERROR_FILE_NAME);
254
255 -----------------------------------------------------------------------
256 -- To open the Debug Session to write the Debug Log. --
257 -- This sets Debug value so that Error_Handler.Get_Debug returns 'Y' --
258 -----------------------------------------------------------------------
259 Error_Handler.Open_Debug_Session(
260 p_debug_filename => G_ERROR_FILE_NAME
261 ,p_output_dir => l_log_output_dir
262 ,x_return_status => l_log_return_status
263 ,x_error_mesg => l_errbuff
264 );
265
266 ---------------------------------------------------------------
267 -- Introduced for 11.5.10, so that Java Conc Program can --
268 -- continue writing to the same Error Log File. --
269 ---------------------------------------------------------------
270 G_ERRFILE_PATH_AND_NAME := l_log_output_dir||'/'||G_ERROR_FILE_NAME;
271
272 developer_debug(' Log file location --> '||l_log_output_dir||'/'||G_ERROR_FILE_NAME ||' created with status '|| l_log_return_status);
273
274 IF (l_log_return_status <> G_RET_STS_SUCCESS) THEN
275 developer_debug('Unable to open error log file. Error => '||l_errbuff);
276 END IF;
277
278 END IF;--IF c_get_utl_file_dir%FOUND THEN
279 -- Bug : 4099546
280 CLOSE c_get_utl_file_dir;
281
282
283 EXCEPTION
284 WHEN OTHERS THEN
285 FND_FILE.put_line(FND_FILE.LOG, 'open_debug_session_internal LOGGING SQL ERROR => ' || SUBSTRB(SQLERRM, 1,240));
286
287 END open_debug_session_internal;
288
289
290 -----------------------------------------------------------
291 -- Open the Debug Session, conditionally if the profile: --
292 -- INV Debug Trace is set to TRUE --
293 -----------------------------------------------------------
294 PROCEDURE Open_Debug_Session
295 ( p_debug_flag IN VARCHAR2 := NULL
296 , p_output_dir IN VARCHAR2 := NULL
297 , p_file_name IN VARCHAR2 := NULL
298 )
299 IS
300
301 BEGIN
302 ----------------------------------------------------------------
303 -- Open the Debug Log Session, only if Profile is set to TRUE --
304 ----------------------------------------------------------------
305 IF (G_DEBUG = 1 OR FND_API.to_Boolean(p_debug_flag)) THEN
306
307
308 G_OUTPUT_DIR := p_output_dir ;
309 G_ERROR_FILE_NAME := p_file_name ;
310 ----------------------------------------------------------------------------------
311 -- Opens Error_Handler debug session, only if Debug session is not already open.
312 -- Suggested by RFAROOK, so that multiple debug sessions are not open PER
313 -- Concurrent Request.
314 ----------------------------------------------------------------------------------
315 IF (Error_Handler.Get_Debug <> 'Y') THEN
316 Open_Debug_Session_Internal;
317 END IF;
318
319 END IF;
320
321 EXCEPTION
322 WHEN OTHERS THEN
323 FND_FILE.put_line(FND_FILE.LOG, 'Open_Debug_Session LOGGING SQL ERROR => ' || SUBSTRB(SQLERRM, 1,240) );
324
325 END Open_Debug_Session;
326
327 -----------------------------------------------------------------
328 -- Close the Debug Session, only if Debug is already Turned ON --
329 -----------------------------------------------------------------
330 PROCEDURE Close_Debug_Session IS
331
332 BEGIN
336 IF (Error_Handler.Get_Debug = 'Y') THEN
333 -----------------------------------------------------------------------------
334 -- Close Error_Handler debug session, only if Debug session is already open.
335 -----------------------------------------------------------------------------
337 Error_Handler.Close_Debug_Session;
338 END IF;
339
340 EXCEPTION
341 WHEN OTHERS THEN
342 FND_FILE.put_line(FND_FILE.LOG, 'Close_Debug_Session LOGGING SQL ERROR => ' || SUBSTRB(SQLERRM, 1,240) );
343
344 END Close_Debug_Session;
345
346 *****************************************************************************/
347
348 -----------------------------------------------------------------
349 -- Replace all Single Quote to TWO Single Quotes, for Escaping --
350 -- NOTE: Used while inserting Strings using Dynamic SQL. --
351 -----------------------------------------------------------------
352 FUNCTION Escape_Single_Quote (p_String IN VARCHAR2)
353 RETURN VARCHAR2 IS
354
355 BEGIN
356
357 IF (p_String IS NOT NULL) THEN
358 ---------------------------------------------------
359 -- Replace all Single Quotes to 2 Single Quotes --
360 ---------------------------------------------------
361 RETURN REPLACE(p_String, '''', '''''');
362
363 ELSE
364 ----------------------------------------------
365 -- Return NULL, if the String is NULL or '' --
366 ----------------------------------------------
367 RETURN NULL;
368 END IF;
369
370 END Escape_Single_Quote;
371
372
373 END DOM_LOG ;