move (rotate|open|close)-log from debug to primitives

These functions need to be compiled after the *data-dir* is defined.
An easy option is to move them to primitives.lisp where other data-dir
related things are defined.
This commit is contained in:
Timo Myyrä 2024-10-22 06:51:48 +03:00
parent 2377e38a26
commit 54a901abd3
2 changed files with 18 additions and 18 deletions

View file

@ -68,20 +68,3 @@ do:
*standard-output* *redirect-stream*
*trace-output* *redirect-stream*
*debug-stream* *redirect-stream*))
(defun rotate-log ()
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*))
(bkp-log-filename (merge-pathnames "stumpwm.log.1" *data-dir*)))
(when (probe-file log-filename)
(rename-file log-filename bkp-log-filename))))
(defun open-log ()
(rotate-log)
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*)))
(setf *debug-stream* (open log-filename :direction :output
:if-exists :supersede
:if-does-not-exist :create))))
(defun close-log ()
(when (boundp '*debug-stream*)
(close *debug-stream*)
(makunbound '*debug-stream*)))

View file

@ -1566,7 +1566,24 @@ of :error."
(ensure-data-dir)
(with-open-file (,s ,(merge-pathnames file *data-dir*)
,@keys)
,@body)))
,@body)))
(defun rotate-log ()
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*))
(bkp-log-filename (merge-pathnames "stumpwm.log.1" *data-dir*)))
(when (probe-file log-filename)
(rename-file log-filename bkp-log-filename))))
(defun open-log ()
(rotate-log)
(let ((log-filename (merge-pathnames "stumpwm.log" *data-dir*)))
(setf *debug-stream* (open log-filename :direction :output
:if-exists :supersede
:if-does-not-exist :create))))
(defun close-log ()
(when (boundp '*debug-stream*)
(close *debug-stream*)
(makunbound '*debug-stream*)))
(defmacro move-to-head (list elt)
"Move the specified element in in LIST to the head of the list."