DBA Data[Home] [Help]

PACKAGE BODY: APPS.INV_LOG_UTIL

Source


1 PACKAGE BODY inv_log_util AS
2 /* $Header: INVLOGUB.pls 120.2 2006/10/13 16:41:35 rambrose noship $ */
3 
4 /** Globals to hold Logging attributs **/
5 g_fd utl_file.file_type;         -- Log file descriptor
6 g_trace_on number := NULL;          -- Log ON state
7 g_dbg_lvl number := 0;
8 g_cp_flag number := 0;
9 g_file_init boolean := false;
10 g_dbgpath varchar2(256) := '_';
11 g_invfile  varchar2(256) := NULL;
12 
13 g_conc_request_id number := FND_GLOBAL.CONC_REQUEST_ID;
14 
15 
16 --
17 -- ***** trace ****
18 -- Looks up the profile values INV_DEBUG_LEVEL, INV_DEBUG_TRACE, and
19 -- INV_DEBUG_FILE and redirects the log-output based on the profile values.
20 -- If this is invoked in the context of a concurrent program, then
21 -- the output is also redirected to the concurrent program's log file
22 --
23 PROCEDURE trace(p_message VARCHAR2,
24                 p_module  VARCHAR2,
25                 p_level   NUMBER := 9) IS
26 
27   l_dbgfile        varchar2(256) ;
28   l_errmsg         varchar2(256);
29   l_timestamp      varchar2(256);
30   l_dbgpath        varchar2(128);
31   l_ndx            number;
32   l_strlen         number;
33   l_dbgdir         varchar2(256);
34   l_dir_separator  varchar2(1);
35   l_session     varchar2(256);
36   l_message     VARCHAR2(2000);
37   --Bug 3559334 fix. Variable not used in code, but resulting in
38   --extra calls to fnd api.
39   --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
40 BEGIN
41   -- Since the forms-server and MWA server recycles database connections
42   -- we need to always check for debug profiles values and see if they
43   -- are different from the values with which it was initialized earlier. If
44   -- different then reinitialize the debug variables
45   IF g_maintain_log_profile AND g_trace_on IS NOT NULL THEN
46     l_dbgpath := g_dbgpath;
47   ELSE
48     g_trace_on := nvl(fnd_profile.value('INV_DEBUG_TRACE'),0);
49     l_dbgpath := fnd_profile.value('INV_DEBUG_FILE') ;
50     if (g_conc_request_id > 0) then
51         g_maintain_log_profile := TRUE;
52     end if;
53 
54   END IF;
55 
56   if ((g_trace_on = 1) AND (l_dbgpath <> g_dbgpath) ) then
57     g_dbgpath := l_dbgpath;
58     g_cp_flag :=  NVL(fnd_profile.value('CONC_REQUEST_ID'), 0) ;
59     if (g_trace_on = 1) then
60     select to_char(sysdate, 'DD-MON-YY:HH.MI.SS'),userenv('SESSIONID') into l_errmsg,l_session from dual;
61       g_dbg_lvl := fnd_profile.value('INV_DEBUG_LEVEL') ;
62 
63       if ( g_cp_flag > 0 ) then
64    FND_FILE.put_line(FND_FILE.LOG, ' ******** New Session:'||l_session||'****'||l_errmsg||' **********');
65       end if;
66 
67       -- Separate the filename from the directory
68       l_strlen := length(l_dbgpath);
69       l_dbgfile := l_dbgpath;
70       l_dir_separator := '/';
71       --Check if separator exits, could be different depending on os
72       l_ndx := instr(l_dbgfile, l_dir_separator);
73       if ( l_ndx = 0 ) then
74         l_dir_separator := '\';
75       end if;
76 
77       loop
78         l_ndx := instr(l_dbgfile, l_dir_separator);
79       exit when ((l_ndx = 0) or (l_ndx is null));
80         l_dbgfile := substr(l_dbgfile, l_ndx+1, l_strlen - l_ndx + 1);
81       end loop;
82 
83       l_dbgdir := substr(l_dbgpath, 1, l_strlen - length(l_dbgfile) - 1);
84 
85       -- Open Log file
86     IF l_dbgdir is not null then
87       if utl_file.is_open(INV_DEBUG_INTERFACE.g_file_handle) then
88           g_fd := INV_DEBUG_INTERFACE.g_file_handle;
89       else
90           g_fd := utl_file.fopen(l_dbgdir, l_dbgfile, 'a');
91       end if;
92       utl_file.put_line(g_fd, '');
93       utl_file.put_line(g_fd, ' ******** New Session:'||l_session||'****'||l_errmsg||' **********');
94      if g_invfile IS NULL then
95        WSH_DEBUG_INTERFACE.Start_Debugger(l_dbgdir,l_dbgfile,g_fd); --call shipping debugger
96       OE_DEBUG_PUB.Start_ONT_Debugger(l_dbgdir,l_dbgfile,g_fd);  -- call OM debugger
97       g_invfile := l_dbgfile;
98      end if;
99 
100       g_file_init := true;
101     END IF;
102 
103     end if;  -- if g_trace_on = 1
104   end if;
105 
106 
107   if (g_trace_on = 1) AND (g_dbg_lvl >= p_level ) then
108 
109      l_timestamp := '[' || to_char(sysdate,'DD-MON-YY HH24:MI:SS') || '] ';
110 
111      -- Bug 3695496: The log file gets truncated if g_miss_char is sent to
112      -- the output file. The text has to be searched and replaced for any
113      -- occurence of fnd_api.g_miss_char -- initialized to chr(0)in the fnd
114      -- API.
115 
116      l_message := REPLACE
117        ( p_message,
118 	 FND_API.G_MISS_CHAR,
119 	 'FND_API.G_MISS_CHAR'
120 	 );
121 
122      --If called from a concurrent program add msg to FND log
123      if ( g_cp_flag > 0 ) then
124         FND_FILE.put_line(FND_FILE.LOG, l_timestamp || p_module ||': '|| l_message);
125         if (g_file_init) then
126 	   utl_file.put_line(g_fd, l_timestamp || p_module ||': '|| l_message);
127 	   utl_file.fflush(g_fd);
128         end if;
129       else
130         if (g_file_init) then
131            utl_file.put_line(g_fd, l_timestamp || p_module ||': '|| l_message);
132            utl_file.fflush(g_fd);
133         end if;
134      end if;
135   end if;
136   --  dbms_output.put_line(p_message);
137 exception
138    when utl_file.INVALID_PATH then
139       null;
140       --    dbms_output.put_line('*** Error: Invalid Path');
141    when others then
142       null;
143       --    l_errmsg := substr(sqlerrm, 1, 240);
144       --    dbms_output.put_line('*** SQL error:'||l_errmsg);
145 END;
146 END inv_log_util;