Files
memex/projects/org-skill-log-aggregator/src/log-aggregator.lisp

18 lines
785 B
Common Lisp

(defun log-scan (&optional (lines 100))
"Reads the last LINES lines of the system log file."
(let ((log-file (merge-pathnames "logs/agent.log" (uiop:getenv "SYSTEM_DIR"))))
(if (uiop:file-exists-p log-file)
(uiop:run-program `("tail" "-n" ,(write-to-string lines) ,(namestring log-file)) :output :string)
"Log file not found.")))
(defun log-summarize (logs)
"Symbolic summary of LOGS focusing on errors and warnings."
(let ((lines (uiop:split-string logs :separator '(#\Newline)))
(errors 0)
(warnings 0))
(dolist (line lines)
(cond
((cl-ppcre:scan "ERROR" line) (incf errors))
((cl-ppcre:scan "WARN" line) (incf warnings))))
(format nil "Log Summary: ~a errors, ~a warnings found in scan." errors warnings)))