Skip to content

Instantly share code, notes, and snippets.

@DarrenN
Forked from Metaxal/logging.rkt
Created May 13, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarrenN/389ce84b77d1ecda35d37ad83fad3770 to your computer and use it in GitHub Desktop.
Save DarrenN/389ce84b77d1ecda35d37ad83fad3770 to your computer and use it in GitHub Desktop.
Simple usage of Racket's logging facility
#lang racket/base
; One way to define a logger
(define lg (make-logger 'my-logger))
; Define a receiver for this logger, along with a log level
(define rc (make-log-receiver lg 'error)) ; also try with 'debug
; Another way to define a logger, with additional forms
(define-logger lg2)
(define rc2 (make-log-receiver lg2-logger 'debug))
; Listen for events on the two log-receivers
(void
(thread
(λ()(let loop ()
(define v (sync rc rc2))
(printf "[~a] ~a\n" (vector-ref v 0) (vector-ref v 1))
(loop)))))
; Set the current logger
(current-logger lg)
; Log messages for the current logger
(log-error "Exterminate!")
(log-fatal "Exterminate! Exterminate!")
(log-debug "What's the red button for?")
; Log messages for lg2 specifically
(log-lg2-info "We're on a mission from God.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment