[racket] Hierarchical loggers

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jul 10 07:11:08 EDT 2014

Yes, I agree that option 1 sounds better.

Every once in a while, I find that option 2 works well with the pattern

 foo.rkt:
   #lang racket
   (define-logger foo) ; uses `(current-logger)`

 bar.rkt:
   #lang racket
   (define-logger bar) ; uses `(current-logger)`

 main.rkt:
   #lang racket
   (require "foo.rkt"
            "bar.rkt")

   (module configure-runtime racket/base
     (define-logger main)
     (current-logger main-logger) ; sets `(current-logger)` early
     ....)

   (require (submod "." configure-runtime))

The `configure-runtime` submodule name is special: when "main.rkt" is
run as a program, then `configure-runtime` is loaded and instantiated
first --- before the result of "main.rkt", and before the imported
"foo.rkt" and "bar.rkt" modules.

This strategy only makes sense for configuration that is especially
main-like, though. It doesn't compose for larger things that are built
on "main.rkt".

At Thu, 03 Jul 2014 13:01:19 +1200, aidalgol at amuri.net wrote:
> What's a sane way to set up hierarchical loggers among a set of modules 
> within a program?  Say the main program file main.rkt has a logger named 
> 'main, and it "require"s module foo which has a logger 'foo, whose 
> parent should be 'main.  Module foo also "require"s module bar, which 
> has its own logger 'bar, whose parent should be 'foo.  The only two ways 
> I can think of achieving this are 1) to have foo and bar provide a 
> procedure that takes a logger and defines the module's logger with the 
> passed logger as its parent, and 2) having each module unconditionally 
> set their loggers parent to the (current-logger) parameter and set that 
> parameter to the parent logger before loading each module.  Option 1 
> seems much saner, but I'd like some advice on this.
> 
> Regards,
> Aidan Gauland
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.