[plt-dev] logging: strings vs. sexps

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Feb 19 16:45:09 EST 2009

On Thu, Feb 19, 2009 at 4:36 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>
> Maybe it's not that `log-message' needs to change, but that the
> `log-error', etc. forms make the wrong thing easy.
>
> Currently,
>
>  (log-error expr)
>
> expands to
>
>  (let ([l (current-logger)])
>    (when (log-level? l 'error)
>      (log-message l 'error expr (current-continuation-marks))))
>
>
> What if we change it to
>
>  (let ([l (current-logger)])
>    (when (log-level? l 'error)
>      (let ([v expr])
>        (log-message l 'error (format "~s" v) v))))
>
> ?
>
> This changes both the formatting and the value supplied to log
> receivers by `log-error'. Programmers who want more control over the
> message and data can still use `log-message'.

Why not make log-error more like error and printf, such that you can write:

(log-error "I got a bad value: ~s" v)

If we're going to use format under the hood anyway, let's give the
user the benefit.

-- 
Carl Eastlund


Posted on the dev mailing list.