[Home] [Help]
PACKAGE BODY: APPS.WIP_LOGGER
Source
1 package body wip_logger as
2 /* $Header: wipflogb.pls 120.0 2005/05/24 19:13:55 appldev noship $ */
3
4 --package variables
5 g_indentLevel NUMBER := 0;
6 g_sessionID NUMBER := -1;
7 type char_tbl_t is table of varchar2(2000) index by binary_integer;
8 g_moduleTbl char_tbl_t;
9 --package constants
10 g_maxMsgLen NUMBER := 255;
11 g_maxIndentLevel NUMBER := 10;
12 g_indentOffset NUMBER := 2;
13 g_anonModule VARCHAR2(30) := 'wip.plsql.anonymous';
14
15 procedure init(x_returnStatus out NOCOPY VARCHAR2);
16
17 procedure write(p_logLevel IN NUMBER,
18 p_msg IN VARCHAR2,
19 x_returnStatus out NOCOPY VARCHAR2);
20
21 procedure log(p_msg IN VARCHAR2,
22 x_returnStatus out NOCOPY VARCHAR2) is
23 begin
24 write(p_logLevel => wip_constants.full_logging,
25 p_msg => p_msg,
26 x_returnStatus => x_returnStatus);
27 end log;
28
29 procedure entryPoint(p_procName IN VARCHAR2,
30 p_params IN param_tbl_t,
31 x_returnStatus out NOCOPY VARCHAR2) is
32 begin
33 x_returnStatus := fnd_api.g_ret_sts_success;
34 g_indentLevel := least(g_indentLevel + 1, g_maxIndentLevel);
35
36 g_moduleTbl(nvl(g_moduleTbl.last, 0) + 1) := 'wip.plsql.' || p_procName;
37
38 write(p_msg => '[begin ' || p_procName || ']',
39 p_logLevel => wip_constants.full_logging,
40 x_returnStatus => x_returnStatus);
41 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
42 raise fnd_api.g_exc_unexpected_error;
43 end if;
44 for i in 1..p_params.count loop
45 write(p_msg => ' ' || p_params(i).paramName || ': ' || p_params(i).paramValue,
46 p_logLevel => wip_constants.full_logging,
47 x_returnStatus => x_returnStatus);
48 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
49 raise fnd_api.g_exc_unexpected_error;
50 end if;
51 end loop;
52
53 exception
54 when others then
55 null;--write() will set all return values properly
56 end entryPoint;
57
58 procedure exitPoint(p_procName IN VARCHAR2,
59 p_procReturnStatus IN VARCHAR2,
60 p_msg IN VARCHAR2,
61 x_returnStatus out NOCOPY VARCHAR2) is
62 begin
63 x_returnStatus := fnd_api.g_ret_sts_success;
64
65 write(p_msg => '[end ' || p_procName || ']',
66 p_logLevel => wip_constants.full_logging,
67 x_returnStatus => x_returnStatus);
68 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
69 raise fnd_api.g_exc_unexpected_error;
70 end if;
71
72 write(p_msg => ' return status: ' || p_procReturnStatus,
73 p_logLevel => wip_constants.full_logging,
74 x_returnStatus => x_returnStatus);
75 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
76 raise fnd_api.g_exc_unexpected_error;
77 end if;
78
79 write(p_msg => ' info: ' || p_msg,
80 p_logLevel => wip_constants.full_logging,
81 x_returnStatus => x_returnStatus);
82 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
83 raise fnd_api.g_exc_unexpected_error;
84 end if;
85
86 --this if should always be true
87 if(g_moduleTbl.last is not null) then
88 g_moduleTbl.delete(g_moduleTbl.last);
89 end if;
90 g_indentLevel := greatest(g_indentLevel - 1, 0);
91 exception
92 when others then
93 --write() will set all return parameters correctly
94 g_indentLevel := greatest(g_indentLevel - 1, 0);
95 end exitPoint;
96
97 procedure cleanUp(x_returnStatus out NOCOPY VARCHAR2) is
98 begin
99 write(p_msg => 'Session ' || g_sessionID || ': ended on ' || to_char(sysdate, 'MM/DD/YYYY HH24:MI:SS'),
100 p_logLevel => wip_constants.full_logging,
101 x_returnStatus => x_returnStatus);
102 g_sessionID := -1;
103 g_indentLevel := 0;
104 g_moduleTbl.delete;
105
106 x_returnStatus := fnd_api.g_ret_sts_success;
107 exception
108 when others then
109 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
110 fnd_msg_pub.add_exc_msg(p_pkg_name => 'wip_logger',
111 p_procedure_name => 'cleanUp',
112 p_error_text => SQLERRM);
113 end cleanUp;
114
115 procedure write(p_logLevel IN NUMBER,
116 p_msg IN VARCHAR2,
117 x_returnStatus out NOCOPY VARCHAR2) is
118 l_msg VARCHAR2(2000);
119 l_module VARCHAR2(2000);
120 begin
121 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
122 if(g_sessionID < 0) then
123 init(x_returnStatus => x_returnStatus);
124 if(x_returnStatus <> fnd_api.g_ret_sts_success) then
125 raise fnd_api.g_exc_unexpected_error;
126 end if;
127 end if;
128 l_msg := 'Session ' || g_sessionID || ': ';
129 l_msg := lpad(l_msg, g_indentLevel * g_indentOffset + length(l_msg), ' ');
130 l_msg := l_msg || substr(p_msg, 0, g_maxMsgLen - length(l_msg));
131 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
132 if(g_moduleTbl.last is null) then
133 g_moduleTbl(1) := g_anonModule;
134 end if;
135
136 -- to work around GSCC, the call to fnd_log.string needs to pass
137 -- accordingly...
138 if ( p_logLevel = FND_LOG.LEVEL_STATEMENT AND
139 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT ) then
140 fnd_log.string(log_level => FND_LOG.LEVEL_STATEMENT,
141 module => g_moduleTbl(g_moduleTbl.last),
142 message => l_msg);
143 elsif ( p_logLevel = FND_LOG.LEVEL_PROCEDURE AND
144 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE ) then
145 fnd_log.string(log_level => FND_LOG.LEVEL_PROCEDURE,
146 module => g_moduleTbl(g_moduleTbl.last),
147 message => l_msg);
148 elsif ( p_logLevel = FND_LOG.LEVEL_EVENT AND
149 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EVENT ) then
150 fnd_log.string(log_level => FND_LOG.LEVEL_EVENT,
151 module => g_moduleTbl(g_moduleTbl.last),
152 message => l_msg);
153 elsif ( p_logLevel = FND_LOG.LEVEL_EXCEPTION AND
154 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EXCEPTION ) then
155 fnd_log.string(log_level => FND_LOG.LEVEL_EXCEPTION,
156 module => g_moduleTbl(g_moduleTbl.last),
157 message => l_msg);
158 elsif ( p_logLevel = FND_LOG.LEVEL_ERROR AND
159 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_ERROR ) then
160 fnd_log.string(log_level => FND_LOG.LEVEL_ERROR,
161 module => g_moduleTbl(g_moduleTbl.last),
162 message => l_msg);
163 elsif ( p_logLevel = FND_LOG.LEVEL_UNEXPECTED AND
164 FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED ) then
165 fnd_log.string(log_level => FND_LOG.LEVEL_UNEXPECTED,
166 module => g_moduleTbl(g_moduleTbl.last),
167 message => l_msg);
168 end if;
169
170 x_returnStatus := fnd_api.g_ret_sts_success;
171 exception
172 when others then
173 x_returnStatus := fnd_api.g_ret_sts_unexp_error;
174 fnd_msg_pub.add_exc_msg(p_pkg_name => 'wip_logger',
175 p_procedure_name => 'write',
176 p_error_text => SQLERRM);
177 end write;
178
179 procedure init(x_returnStatus out NOCOPY VARCHAR2) is
180 begin
181 x_returnStatus := fnd_api.g_ret_sts_success;
182 g_indentLevel := 0;
183
184 if(g_sessionID < 0) then
185 select wip_logging_session_s.nextval
186 into g_sessionID
187 from dual;
188 end if;
189 write(p_msg => 'Session ' || g_sessionID || ': started on ' || to_char(sysdate, 'MM/DD/YYYY HH24:MI:SS'),
190 p_logLevel => wip_constants.trace_logging,
191 x_returnStatus => x_returnStatus);
192 end init;
193 end wip_logger;