-
Notifications
You must be signed in to change notification settings - Fork 0
/
MVLOG
121 lines (112 loc) · 3.86 KB
/
MVLOG
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
SUBROUTINE MVLOG(LOG.TAG, LOG.LEVEL, LOG.TEXT, LOG.PGM, LOG.ID, LOG.MSG, RV4, RV3, RV2, RV1)
* Logging utility
*********************************************************************
* Description
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* TODO
*********************************************************************
* Arguments
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* This subroutine must be called with those arguments:
* TAG (in): Small keyword to identify the log record.
* LEVEL (in): Level of priority for log. Standard entries:
* FATAL, ERROR, WARN, INFO, DEBUG.
* TEXT (in): Whatever you want to be logged.
* PGM (in): Program that calls that subr.
* ID (in/out): ID of the log record.
* MSG (out): Message to the calling program if something
* went wrong. Otherwise, it's "OK".
* RV4 (in): Reserved for future.
* RV3 (in): Reserved for future.
* RV2 (in): Reserved for future.
* RV1 (in): Reserved for future.
*********************************************************************
* Parameters
EQU FILE.NAME TO "LOG.DETAIL" ;* File name where to store logs.
EQU DEFAULT.LEVEL TO "INFO" ;* Level to use if passed level is not valid.
*********************************************************************
* Validate if target file exists. If the VOC entry is not type F
* or type Q, we will not be able to write to that target, end program.
FTEST = TRANS("VOC", FILE.NAME, 1, "X")
FTEST = UPCASE(LEFT(FTEST,1))
IF FTEST # "F" AND FTEST # "Q" THEN
LOG.MSG = "Target '":FILE.NAME:"' is not a file!"
RETURN
END
* Retrive data from parameters.
THIS.DATE = @DATE
THIS.TIME = @TIME
THIS.USER = @LOGNAME
THIS.ACCT = @ACCOUNT
THIS.TAG = UPCASE(LOG.TAG)
THIS.PGM = UPCASE(LOG.PGM)
THIS.LOG = LOG.TEXT
THIS.LEVEL= UPCASE(LOG.LEVEL)
* Clean Level
LEVELS=""
LEVELS<-1> = "FATAL"
LEVELS<-1> = "WARN"
LEVELS<-1> = "ERROR"
LEVELS<-1> = "INFO"
LEVELS<-1> = "DEBUG"
LEVEL.NDX = 0
LOCATE(THIS.LEVEL, LEVELS;LEVEL.NDX) ELSE
LOG.MSG = "Level '":THIS.LEVEL:"' is not valid."
THIS.LEVEL = DEFAULT.LEVEL
END
* Create the record ID
* -------------------------------------------------------------------
IF LOG.ID = "" THEN
* Retrieve Tag control record from the DICT part
DICT.KEY = "$$TAG*":THIS.TAG
OPEN "DICT ":FILE.NAME TO DICT.FILE ELSE STOP "CANNOT OPEN DICT!"
READ DICT.REC FROM DICT.FILE,DICT.KEY ELSE DICT.REC = ""
* If the returned record is empty, set attr 1 to 0.
IF DICT.REC = "" THEN
DICT.REC<1> = "X"
DICT.REC<2> = 0
END
* Calculate the new sequential number
SEQ.NUMBER = DICT.REC<2>+1
* Set the new sequantial number for that tag
DICT.REC<2> = SEQ.NUMBER
* Save the new tag data.
WRITE DICT.REC TO DICT.FILE,"$$TAG*":THIS.TAG
CLOSE DICT.FILE
* Create the Key
THIS.KEY = THIS.TAG:RIGHT(("000000":SEQ.NUMBER),6)
* Set O.ID to return to calling program.
LOG.ID = THIS.KEY
END ELSE
THIS.KEY = LOG.ID
END
* Read the log record from the file
OPEN FILE.NAME TO LOG.FILE ELSE STOP "CAN'T OPEN LOG FILE!"
READU LOG.REC FROM LOG.FILE,THIS.KEY ELSE LOG.REC = ""
* If no record is read, create a new record.
IF LOG.REC = "" THEN
LOG.REC<1> = THIS.DATE ;* Start Date
LOG.REC<2> = THIS.TIME ;* Start Time
LOG.REC<3> = THIS.ACCT
LOG.REC<4> = THIS.PGM
LOG.REC<5> = THIS.USER
LOG.REC<6> = THIS.TAG
LOG.REC<7> = THIS.LEVEL
LOG.REC<8> = THIS.LOG
LOG.REC<9> = THIS.DATE ;* End Date
LOG.REC<10> = THIS.TIME ;* End Time
END ELSE
* If a record is read, append info to MV data and update
* End Date/Time.
LOG.REC<7,-1> = THIS.LEVEL
LOG.REC<8,-1> = THIS.LOG
LOG.REC<9> = THIS.DATE ;* End Date
LOG.REC<10> = THIS.TIME ;* End time
END
* Save the new log record
WRITE LOG.REC TO LOG.FILE, THIS.KEY
CLOSE LOG.FILE
* Set the OK message because everything is OK.
IF LOG.MSG = "" THEN LOG.MSG = "OK"
*********************************************************************
END