[plt-scheme] How to use the new logging stuff to log to a file?

From: Eric Hanchrow (offby1 at blarg.net)
Date: Sat Jul 26 23:38:22 EDT 2008

To use the new logging stuff to log to a file, do I write a separate
thread that waits on the log-receiver, emits the data, and then loops?
That seems the simplest way.  And yet Eli says "I wonder what's the
difference between that and just a thread using its mailbox for
messages", which is a good point ...

Here's what I mean (which seems to work fine):

    (define *debug-receiver* (make-log-receiver (current-logger) 'debug))

    (define *debug-file-name* "debug-spew")

    (define *debug-thread*
      (thread
       (lambda ()
         (let loop ()
           (let ((datum (sync *debug-receiver*)))
             (call-with-output-file
                 *debug-file-name*
               (lambda (op)
                 (fprintf op "Debug: ~s~%" datum))
               #:exists 'append)
             (loop))))))
-- 
If you're trying to choose between two theories and one gives
you an excuse for being lazy, the other one is probably right.
        -- Paul Graham


Posted on the users mailing list.