Re: Logging librarie (Re: Debugging COMM:START-UP-SERVER hang)

"Tim Bradshaw (as tfb at cley dot com)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
On 28 Feb 2026, at 21:22, Alexey Veretennikov (as alexey dot veretennikov at protonmail dot com) <[email protected]> wrote:
> 
> Personally I don't like too much dependencies, so I just run a logging thread/process with a mailbox where I send anything I want to log (or eventual shutdown message), take out a message in a loop and print it. Seems easier than to learn yet another library.

I have the advantage of having written slog (so I'm blowing my own trumpet here), but this is exactly one of the ways I've used it:

(defmethod slog-to ((destination mailbox)
                    (entry log-entry)
                    &key)
  ;; a mailbox is now a log destination
  (mailbox-send destination entry)
  entry)

(define-condition terminating-log-entry (log-entry)
  ;; Just a marker
  ())

(defun mailbox-log-reader (mailbox &optional (stream *debug-io*))
  ;; Read log entries and print them till we get a terminating entry
  (do ((entry (mailbox-read mailbox) (mailbox-read mailbox)))
      ((typep entry 'terminating-log-entry))
    (slog-to stream entry)))

(defvar *log-mailbox* (make-mailbox))

(defun ts (n (mailbox *log-mailbox*))
  (process-run-function
   "foo" ()
   (lambda ()
     ...
     (logging ((t mailbox))
       ...
       (slog "World exploded again")
       ...
       (slog 'terminating-log-entry)))))

Slog's trick is that log entries are conditions and logging is signalling them.  LOGGING then establishes condition handlers (which always decline to handle the condition so control flow just continues) which deal with log entries.

It may be that other logging frameworks do the same thing, but they all looked too complicated to understand.  The S in slog is for *simple*: I wanted to be able to log events not to deal with some awful bureaucracy which has seeped out from the Java mines.

--tim

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.