dbuenzli / logs

Logging infrastructure for OCaml
http://erratique.ch/software/logs
ISC License
86 stars 19 forks source link

consider moving the format inside 'a msgf #7

Closed edwintorok closed 8 years ago

edwintorok commented 8 years ago

I'd like to be able to write something like:

Logs.debug (fun m -> m "The value is %d" 42);

Instead of:

Logs.debug "The value is %d" (fun m ->m 42);

It seems more natural to keep the format string and arguments together, although I'm not sure how this change would affect the internals of Logs.

dbuenzli commented 8 years ago

Kind of agree with you. I'll see if that's workable, and switch to that asap. Thanks for the feedback.

dbuenzli commented 8 years ago

I think this could also allow to remove the Logs.unit for constant formats, since there will always be at least one unlabelled argument to m.

dbuenzli commented 8 years ago

I have a branch here that does that. I quite like the result since it removes the need for Logs.unit and generally simplifies the interface. I still need to update the documentation properly and my own code and then I'll merge that in master.

dbuenzli commented 8 years ago

So I merged this into master. I'd say that the code looks much better in general. However we loose the ability to abstract logging instruction e.g.:

let log_err_whatever = Logs.err fmt 

So I'm still a little bit undecided.

edwintorok commented 8 years ago

Isn't it possible to implement the old signature on top of the new one?

let old_log_err fmt f = Logs.err (fun m -> f (m fmt));

Perhaps you could provide a variant of kmsg with the old semantics implemented on top of the new kmsg, then users of Logs can decide which one is more convenient to use in their abstract logging instructions.

dbuenzli commented 8 years ago

I think I'll simply document the pattern for partially applying the formatter which is basically as you mention:

let log_err_bla m = Logs.err (fun m' -> m (m' $FMT))