Skip to content

Commit 5180de1

Browse files
authored
Merge pull request #13 from RoelantVos/load_window_addition
Added procedure to log events in event log table
2 parents c19d22c + 02fe2d1 commit 5180de1

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
0 Bytes
Binary file not shown.

020_DIRECT_Framework/Direct_Framework/Direct_Framework.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<Build Include="Functions\omd.GetPreviousBatchInstanceDetails.sql" />
144144
<Build Include="Stored Procedures\omd.CreateLoadWindow.sql" />
145145
<Build Include="Functions\GetModuleAreaByModuleId.sql" />
146+
<Build Include="Stored Procedures\omd.InsertIntoEventLog.sql" />
146147
</ItemGroup>
147148
<ItemGroup>
148149
<PostDeploy Include="Scripts\Script.PostDeployment.sql" />
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Process: Create a new entry in the Event Log
3+
Purpose: Inserts a log entry capturing failures or other noteworthy events.
4+
Input:
5+
- Module Instance Id
6+
- Event Details
7+
Optional:
8+
- Event Datetime (defaults to SYSDATETIME if not set)
9+
- Batch Instance Id
10+
- Event Type Code (1,2,3 etc. see omd.EVENT_TYPE table contents for options)
11+
- Error Return Code
12+
- Error Bitmap
13+
- Debug flag Y/N (default to N)
14+
Returns:
15+
- Default Stored Procudure return code (no specific output)
16+
Usage:
17+
EXEC [omd].[InsertIntoEventLog]
18+
@ModuleInstanceId = <>,
19+
@EventCode = '<>'
20+
*/
21+
22+
CREATE PROCEDURE [omd].[InsertIntoEventLog]
23+
@ModuleInstanceId INT,
24+
@EventDetail VARCHAR(4000),
25+
@BatchInstanceId INT = 0,
26+
@EventDateTime DATETIME = NULL,
27+
@EventTypeCode VARCHAR(10) = '2',
28+
@EventReturnCode VARCHAR(1000) = 'N/A',
29+
@ErrorBitmap NUMERIC(20,0) = 0,
30+
@Debug VARCHAR(1) = 'Y'
31+
AS
32+
33+
BEGIN
34+
35+
-- Handling the Event Date Time
36+
IF @EventDateTime IS NULL
37+
SET @EventDateTime = SYSDATETIME();
38+
39+
BEGIN
40+
BEGIN TRY
41+
IF @Debug='Y'
42+
BEGIN
43+
PRINT 'Inserting record in Event Log for Module Instance Id '+CONVERT(VARCHAR(10),@ModuleInstanceId)+' with message '+@EventDetail+'.';
44+
END
45+
46+
INSERT INTO [omd].[EVENT_LOG]
47+
(
48+
[MODULE_INSTANCE_ID]
49+
,[BATCH_INSTANCE_ID]
50+
,[EVENT_TYPE_CODE]
51+
,[EVENT_DATETIME]
52+
,[EVENT_RETURN_CODE_DETAILS]
53+
,[EVENT_DETAIL]
54+
,[ERROR_BITMAP]
55+
)
56+
VALUES
57+
(
58+
@ModuleInstanceId,
59+
@BatchInstanceId,
60+
@EventTypeCode,
61+
@EventDateTime,
62+
@EventReturnCode,
63+
@EventDetail,
64+
@ErrorBitmap
65+
)
66+
67+
END TRY
68+
BEGIN CATCH
69+
THROW
70+
END CATCH
71+
END
72+
73+
END

020_DIRECT_Framework/Direct_Framework/Stored Procedures/omd.RunModule.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ BEGIN
8181
@EventCode = 'Failure';
8282

8383
SET @QueryResult = 'Failure';
84+
85+
-- Logging
86+
DECLARE @EventDetail VARCHAR(4000) = ERROR_MESSAGE(),
87+
@EventReturnCode int = ERROR_NUMBER();
88+
89+
EXEC [omd].[InsertIntoEventLog]
90+
@ModuleInstanceId = @ModuleInstanceId,
91+
@EventDetail = @EventDetail,
92+
@EventReturnCode = @EventReturnCode;
93+
8494
THROW
8595
END CATCH
8696
ELSE

0 commit comments

Comments
 (0)