Logging to files
| OPEN EXTEND | |
| Log line format | |
| Log hygiene |
OPEN EXTEND
A log is a sequential file opened EXTEND, so every run appends after the last. Declare it like any other file and write one record per event:
SELECT LOG-FILE ASSIGN TO "payroll.log"
ORGANIZATION IS LINE SEQUENTIAL.
OPEN EXTEND LOG-FILE.
Log line format
Start every record with a timestamp from CURRENT-DATE, then a severity word, then the message. Fixed fields make the log greppable years later:
STRING WS-STAMP(1:14) " INFO " WS-MESSAGE
DELIMITED BY SIZE INTO LOG-RECORD.
WRITE LOG-RECORD.
Log hygiene
Close the log at the end of every run, even after errors, so no records are lost. Cap the file size from the scheduler, and never log full account numbers or salaries in production systems.
Next: CSV parsing
Article author: Arthur Isaev