DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_DEBUG_PUB

Source


1 PACKAGE BODY OKL_DEBUG_PUB as
2 /* $Header: OKLPDEGB.pls 120.2 2005/10/30 04:23:53 appldev noship $ */
3 -- Start of Comments
4 -- Package name     : OKL_DEBUG_PUB
5 -- Purpose          :
6 -- History          :
7 -- NOTE             :
8 -- End of Comments
9 
10 
11 DB_NAME VARCHAR2(80) := 'OKL';
12 
13 Function OpenFile(P_File in varchar2  ) Return Varchar2 IS
14 rtn_val   Varchar2(100);
15 Begin
16 
17        if G_DIR is null then
18             select value  INTO G_DIR
19  	        from v$PARAMETER where name = 'utl_file_dir';
20 	       if instr(G_DIR,',') > 0 then
21  	           G_DIR := substr(G_DIR,1,instr(G_DIR,',')-1);
22  	       end if;
23        END IF;
24 
25 
26       if P_FILE is null then
27          -- select substr('l'|| substr(to_char(sysdate,'MI'),1,1)
28            --        || lpad(OKL_DEBUG_file_s.nextval,6,'0'),1,8) ||  '.IEX'
29            --into G_FILE from dual;
30 
31             SELECT DB_NAME || USERENV('SESSIONID') || '.OKL' into G_FILE
32             FROM   DUAL;
33 
34            G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'w');
35       else
36            G_FILE :=P_File;
37            G_FILE_PTR := utl_file.fopen(G_DIR, G_FILE, 'a');
38       end if;
39 
40       rtn_val := G_DIR || '/' || g_file;
41 
42 
43     return(rtn_val);
44  Exception
45      WHEN OTHERS then
46           return(null);
47 End OpenFile;
48 
49 Procedure SetDebugFileDir(P_FILEDIR IN VARCHAR2) IS
50 
51 BEGIN
52    if p_FileDir IS not null then
53 	G_DIR := p_FileDir;
54    end if;
55 END;
56 
57 
58 --  PROCEDURE  LogMessage
59 --
60 --  Usage       Used to log message to the debug  file
61 
62 PROCEDURE LogMessage(debug_msg   in Varchar2,
63               debug_level in Number default 10,
64               print_date  in varchar2 default 'N')
65 
66 IS
67 rtn_val   Varchar2(100);
68 BEGIN
69 
70 
71   if (G_Debug_Level <= debug_level) then
72       rtn_val:=OpenFile(G_FILE);
73 
74       if print_date = 'Y' then
75          utl_file.put_line(G_FILE_PTR, to_char( sysdate, 'DD-MON-YYYY HH:MI:SS' )  || ' ' || debug_msg );
76 
77    	  else
78 	      utl_file.put_line(G_FILE_PTR, ' ' ||debug_msg);
79   	  end if; --if print date is 'Y'
80 
81       -- Write and close the file
82        utl_file.fflush(G_FILE_PTR);
83        utl_file.fclose(G_FILE_PTR);
84 
85   end if;-- debug level is big enough
86 
87 Exception
88  WHEN OTHERS then
89        null;
90 END LogMessage; -- LogMessage
91 
92 /*Inserted by SPILLAIP Begin*/
93 --
94 -- This function checks the profile value of FND: Debug_Enabled
95 -- and returns boolean
96 --
97 FUNCTION CHECK_LOG_ENABLED
98  RETURN varchar2 IS
99  value varchar2(40) := 'N';
100 BEGIN
101   fnd_profile.get('AFLOG_ENABLED',value);
102   return value;
103 EXCEPTION
104   when others then
105     return 'N';
106 END;
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       g_profile_log_level := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
141 
142     End If;
143    End;
144 
145 --
146 --Function Check_Log_On checks if the module is enabled for the
147 -- level specified.  This function returns boolean.
148 --
149 FUNCTION CHECK_LOG_ON
150   ( p_module IN varchar2,
151     p_level IN number)
152    RETURN  boolean IS
153    log_enabled boolean := false;
154 BEGIN
155   log_enabled := fnd_log.test(p_level,p_module);
156    if (log_enabled) then
157       return true;
158    else
159       return false;
160    end if;
161 Exception
162   when others then
163      return false;
164 end;
165 
166 --
167 -- Log_debug procedure log the debug to FND_LOG.  This procedure
168 -- does not check if debug is enabled.
169 --
170 PROCEDURE LOG_DEBUG
171   ( p_log_level IN number,
172     p_module IN varchar2,
173     p_message IN varchar2) IS
174 BEGIN
175     --
176     -- First thing, set the connection context
177     --
178     Set_Connection_Context;
179 
180    if (check_log_on(p_module, p_log_level)) then
181 	if(p_log_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then
182       		fnd_log.string(p_log_level,p_module,p_message);
183   	 end if;
184    end if;
185 END;
186 
187 
188 /*Inserted by SPILLAIP End*/
189 
190 --  PROCEDURE   SetDebugLevel
191 --
192 --  Usage       set debug level if running outside of application otherwise debuglevel
193 --              is taken from the profile value
194 
195 Procedure SetDebugLevel(p_debug_level in number)
196 IS
197 Begin
198   OKL_DEBUG_PUB.G_DEBUG_LEVEL := p_debug_level;
199 End SetDebugLevel;
200 
201 BEGIN
202    SELECT NAME INTO DB_NAME FROM V$DATABASE;
203    DB_NAME := DB_NAME || '_';
204 
205 END OKL_DEBUG_PUB;