[plt-scheme] Is there a logging tool?

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Thu Jul 31 07:01:11 EDT 2008

As part of my testing suite, I also needed a logger, since each  
client runs in its own thread. In a Java application, I might use  
something like log4j, but I didn't find anything like that in the  
documentation, so I put together this quick and dirty solution:

;;Trivial logger - replace with something more sophisticated.
(define (make-trivial-logger fname)
   (lambda (lvl msg)
     ;be sure not to overwrite the log file
     (call-with-output-file fname #:exists 'append
       (lambda (out)
         (begin
           (cond
             ((eq? lvl 'info) (fprintf out "INFO "))
             ((eq? lvl 'warn) (fprintf out "WARN "))
             ((eq? lvl 'error) (fprintf out "ERROR "))
             (else (fprintf out "UNKNOWN ")))
           (fprintf out "~a" msg)
           ;include time
           (fprintf out " ~a~n" (date->string (seconds->date (current- 
seconds)) #t)))))))

It's not pretty because it opens the log file on each invocation. An  
alternative I  considered is starting a logger thread and then using  
thread mailboxes to deliver messages to it, but then it's not clear  
to me how to go about closing the file and shutting down the logger  
thread when it's no longer needed.

But does a tool like this already exist? It seems like a common  
enough task.


"Interaction is the mind-body problem
of computing." --Philip  L. Wadler

http://www.gwoodhouse.com
http://GregWoodhouse.ImageKind.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080731/eac771a8/attachment.html>

Posted on the users mailing list.