BASIC · lesson 28 of 30 · Tools for the NASSummarise a log
Count the levels with switch and show the text of every error.
28-log-summary.yab Download 28-log-summary.yab
rem Counts the levels in a log and shows the errors
dim part$(1)
open #1, "nas.log", "r"
while not eof(1)
line input #1 line$
n = token(line$, part$(), " ")
switch part$(3)
case "INFO": info = info + 1: break
case "WARN": warn = warn + 1: break
case "ERROR"
errors = errors + 1
print part$(1), " ", mid$(line$, instr(line$, "ERROR") + 6)
break
end switch
wend
close #1
print info, " info, ", warn, " warnings, ", errors, " errors"
Terminal
$ yabasic 28-log-summary.yab
2027-01-04 share Documents is full
2027-01-05 backup stopped: no space
2027-01-06 disk 3 read error
6 info, 3 warnings, 3 errorsExercise
Print only the lines of one day, given as an argument.