1 package body ARP_DEBUG as
2 /* $Header: ARDBGMGB.pls 120.1 2006/06/09 03:54:53 mraymond noship $ */
3
4 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
5
6
7 /*-------------------------------------------------------------------------+
8 | |
9 | PRIVATE FLAGS |
10 | |
11 | Control flags are currently held in base 10. |
12 | PUBLIC FUNCTIONS are declared to export each of these private flags |
13 | to a SQL*ReportWriter application. |
14 | |
15 +-------------------------------------------------------------------------*/
16
17 INT_MD_MSG_NUMBER constant number := 1; -- Message Dictionary control
18 INT_MD_MSG_TEXT constant number := 10; -- Options
19 INT_MD_MSG_NAME constant number := 100; -- Show message name only
20 INT_MD_MSG_TOKENS constant number := 1000; -- List Message Tokens and Values
21 INT_MD_MSG_EXPLANATION constant number := 10000; -- Not supported yet
22 INT_MD_MSG_FIND_NUMBER constant number := 100000; -- Use Message Number not Name
23
24
25 /*-------------------------------------------------------------------------+
26 | |
27 | PRIVATE VARIABLES |
28 | |
29 +-------------------------------------------------------------------------*/
30
31 debug_flag boolean := false;
32
33 pg_file_name VARCHAR2(100) := NULL;
34 pg_path_name VARCHAR2(100) := NULL;
35 pg_fp utl_file.file_type;
36
37 procedure file_debug(line in varchar2) IS
38 x number;
39 begin
40 if (pg_file_name is not null) THEN
41 utl_file.put_line(pg_fp, line);
42 utl_file.fflush(pg_fp);
43 end if;
44 end file_debug;
45
46
47
48 /*-------------------------------------------------------------------------+
49 | |
50 | PUBLIC FUNCTIONS |
51 | |
52 +-------------------------------------------------------------------------*/
53
54 procedure enable_file_debug(path_name in varchar2,
55 file_name in varchar2) IS
56
57 x number;
58 begin
59
60 if (pg_file_name is null) THEN
61 pg_fp := utl_file.fopen(path_name, file_name, 'a');
62 pg_file_name := file_name;
63 pg_path_name := path_name;
64 end if;
65
66
67 exception
68 when utl_file.invalid_path then
69 app_exception.raise_exception;
70 when utl_file.invalid_mode then
71 app_exception.raise_exception;
72
73 end ;
74
75
76 procedure disable_file_debug is
77 begin
78 if (pg_file_name is not null) THEN
79 utl_file.fclose(pg_fp);
80 end if;
81 end;
82
83
84 procedure debug( line in varchar2,
85 msg_prefix in varchar2,
86 msg_module in varchar2,
87 msg_level in number
88 ) is
89 l_msg_prefix varchar2(64);
90 l_msg_level number;
91 l_msg_module varchar2(256);
92 l_beg_end_suffix varchar2(15);
93 l_org_cnt number;
94 l_line varchar2(32767);
95
96 begin
97
98 l_line := line;
99
100 /* ----------------------------------------------------
101 For file debug the messages are written both on file
102 and FND tables.
103 ----------------------------------------------------*/
104
105 IF (pg_file_name IS NOT NULL) THEN
106 file_debug(l_line);
107 END IF;
108
109 l_msg_prefix := 'a' || 'r' || '.' || msg_prefix || '.';
110
111 /* EXCEPTIONS:
112 - if length of message > 99
113 - if text contains (s)
114 */
115 IF lengthb(l_line) > 99 OR
116 INSTRB(l_line, '(s)') <> 0
117 THEN
118 l_msg_level := FND_LOG.LEVEL_STATEMENT;
119 l_msg_module := l_msg_prefix || NVL(g_msg_module, 'UNKNOWN');
120
121 -- This logs the message
122 /* Bug 4361955 */
123 IF ( l_msg_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL )
124 THEN
125 FND_LOG.STRING(l_msg_level, l_msg_module, substr(l_line,1,4000));
126 END IF;
127
128 RETURN;
129 END IF;
130
131 -- set msg_level for this message
132 IF (msg_level IS NULL)
133 THEN
134 IF (INSTRB(upper(l_line), 'EXCEPTION') <> 0)
135 THEN
136 l_msg_level := FND_LOG.LEVEL_EXCEPTION;
137 ELSIF (INSTRB(l_line, ')+') <> 0 OR
138 INSTRB(l_line, '+)') <> 0)
139 THEN
140 l_msg_level := FND_LOG.LEVEL_PROCEDURE;
141 l_beg_end_suffix := '.begin';
142 ELSIF (INSTRB(l_line, ')-') <> 0 OR
143 INSTRB(l_line, '-)') <> 0)
144 THEN
145 l_msg_level := FND_LOG.LEVEL_PROCEDURE;
146 l_beg_end_suffix := '.end';
147 ELSE
148 l_msg_level := FND_LOG.LEVEL_STATEMENT;
149 l_beg_end_suffix := NULL;
150 END IF;
151 ELSE
152 /* Verify that level is between 1 and 6 */
153 IF msg_level >= 1 AND msg_level <= 6
154 THEN
155 l_msg_level := msg_level;
156 ELSE
157 /* Invalid message level, default 1 */
158 l_msg_level := 1;
159 END IF;
160 END IF;
161
162 -- set module for this message
163 IF (msg_module IS NULL)
164 THEN
165
166 -- chop off extraneous stuff on right end of string
167 l_msg_module := SUBSTRB(RTRIM(l_line), 1,
168 INSTRB(l_line, '(') - 1);
169
170 -- chop off extraneous stuff on left
171 l_msg_module := SUBSTRB(l_msg_module,
172 INSTRB(l_msg_module, ' ', -3 ) + 1);
173
174 /* If we were unable to get a module name, use
175 the global (previously stored) one */
176 IF l_msg_module IS NULL
177 THEN
178 l_msg_module := NVL(g_msg_module, 'UNKNOWN');
179 ELSE
180 g_msg_module := l_msg_module;
181 END IF;
182
183 l_msg_module := l_msg_prefix || l_msg_module || l_beg_end_suffix;
184 ELSE
185 l_msg_module := l_msg_prefix || msg_module;
186 END IF;
187
188 -- This actually logs the message
189 /* Bug 4361955 */
190 IF ( l_msg_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL )
191 THEN
192 FND_LOG.STRING(l_msg_level, l_msg_module, l_line);
193 END IF;
194
195
196 exception
197 when others then
198 raise;
199 end;
200
201
202 END ARP_DEBUG;