diff --git a/check_router_reboot.jl b/check_router_reboot.jl index 84d13d9..84d3240 100644 --- a/check_router_reboot.jl +++ b/check_router_reboot.jl @@ -328,19 +328,33 @@ function perform_check!(st::State) # println(5) end - function limitTextFileLines(LogFilePath::String; maxlines::Integer=100) log = readlines(LogFilePath) - if length(log) < (maxlines - 1) + total_lines = length(log) + if total_lines < maxlines return nothing end + exceeding_row = total_lines - maxlines # can be 0 or more + reduced_lines = log[exceeding_row+2:end] reducedLog = "" - for i in log[end-(maxlines-1):end] + for i in reduced_lines reducedLog = reducedLog * i * "\n" end write(LogFilePath, reducedLog) end +# function limitTextFileLines(LogFilePath::String; maxlines::Integer=100) +# log = readlines(LogFilePath) +# if length(log) < (maxlines - 1) +# return nothing +# end +# reducedLog = "" +# for i in log[end-(maxlines-1):end] +# reducedLog = reducedLog * i * "\n" +# end +# write(LogFilePath, reducedLog) +# end + # Main loop: runs indefinitely every CHECK_INTERVAL_SECS function main_loop() # Ensure log file exists