-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlogger.cbl
61 lines (61 loc) · 2.31 KB
/
logger.cbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
******************************************************************
* Author: Lauryn Brown
* Date:
* Purpose: log activity done by other programs
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LOGGER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OPTIONAL LOG-FILE ASSIGN TO DYNAMIC WS-LOG-FILE-NAME
ORGANISATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD LOG-FILE.
01 LOG-RECORD.
02 LOG-RECORD-ID PIC 9(10).
02 LOG-RECORD-FUNCTION-NAME PIC X(40).
02 LOG-RECORD-MESSAGE PIC X(100).
WORKING-STORAGE SECTION.
01 WS-LOG-FILE-NAME PIC X(20).
LINKAGE SECTION.
01 LS-LOG-OPERATION-FLAG PIC X(5).
01 LS-LOG-RECORD.
02 LS-LOG-RECORD-FUNCTION-NAME PIC X(40).
02 LS-LOG-RECORD-MESSAGE PIC X(100).
PROCEDURE DIVISION USING LS-LOG-OPERATION-FLAG, LS-LOG-RECORD.
MAIN-PROCEDURE.
EVALUATE LS-LOG-OPERATION-FLAG
WHEN "OPEN"
PERFORM LOG-INIT-PROCEDURE
WHEN "CLOSE"
PERFORM LOG-CLOSE-PROCEDURE
WHEN "ADD"
PERFORM LOG-WRITE-TO-PROCEDURE
WHEN OTHER
PERFORM LOG-FLAG-ERROR-PROCEDURE.
GOBACK.
LOG-INIT-PROCEDURE.
MOVE '..\logs\log.data' TO WS-LOG-FILE-NAME.
OPEN OUTPUT LOG-FILE.
MOVE 1 TO LOG-RECORD-ID.
MOVE "LOG-INIT-PROCEDURE" TO LOG-RECORD-FUNCTION-NAME.
MOVE "Starting Program!" TO LOG-RECORD-MESSAGE.
WRITE LOG-RECORD.
LOG-WRITE-TO-PROCEDURE.
ADD 1 TO LOG-RECORD-ID.
MOVE LS-LOG-RECORD-FUNCTION-NAME TO LOG-RECORD-FUNCTION-NAME.
MOVE LS-LOG-RECORD-MESSAGE TO LOG-RECORD-MESSAGE.
WRITE LOG-RECORD.
LOG-FLAG-ERROR-PROCEDURE.
DISPLAY "READ FLAG ERROR".
LOG-CLOSE-PROCEDURE.
ADD 1 TO LOG-RECORD-ID.
MOVE "LOGGER:LOG-CLOSE-PROCEDURE"
TO LOG-RECORD-FUNCTION-NAME.
MOVE "Closed logging file" TO LOG-RECORD-MESSAGE.
WRITE LOG-RECORD.
CLOSE LOG-FILE.
END PROGRAM LOGGER.