Yes, the default logger cheats. When you log a relevant message, it's
written immediately to stdout/stderr/syslog instead of being posted to
a receiver that is later polled.

At Thu, 17 Jan 2019 17:59:30 -0800 (PST), Brian Adkins wrote:
> I've created my own logger via make-logger, and I started a thread with a 
> loop that sync's on the log receiver I created via make-log-receiver. I'm 
> logging some messages in a test, and it appears that the test completes 
> (and presumably kills the log receiver thread) before the log message is 
> displayed. I'm calling (flush-output) after printf'ing the message to 
> standard out.
> 
> The default logger does not have this problem. Is that because it doesn't 
> use a separate thread to sync on the log messages and display them? Or am I 
> misunderstanding how to best utilize a custom logger?
> 
> I've copy/pasted some code below for specifics.
> 
> Thanks,
> Brian
> 
> (define axio-logger (make-logger 'axio))
> 
> (define/contract (axio-log-debug str)
>   (-> string? any)
>   (log-message axio-logger 'debug str #f))
> 
> ...
> 
> (define/contract (axio-init-logger level)
>   (-> symbol? any)
>   (define axio-log-receiver (make-log-receiver axio-logger level))
>   
>   (thread
>    (λ ()
>      (let loop ()
>        (define v (sync axio-log-receiver))
>        (printf "[~a] ~a\n" 
>                (vector-ref v 0)
>                (vector-ref v 1))
>        (flush-output)
>        (loop)))))
> 
> 
> (axio-log-debug "my log message")
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to