OCaml / Async Registration Events

I use the global module Log.Globaland functions infoand debug, but my application is growing and I need more flexibility. In particular, I would like to be able to enable / disable events from different components of the system. I am wondering what is the best practice in general (I mention Async, since this is the API that I use, but the question is more general).

The API seems to provide at least two ways to do this. There are optional parameters ?tags:(string * string) list. When used, it adds tags after the log message.

2017-08-23 17:35:38.090225+07:00 Info starting my program -- [foobar: foobar]

I could use this and then filter my log based on the events I want to see. How are tags usually used, are they usually literals, or are there other ways to use them?

I could also use more than one registrar. For example, a functor Make_global () : Global_intfcreates a singleton. I can create one registrar for each component. Is there any good reason to choose this approach? besides the fact that each log has a different output and the log level setting is independent.

+4
source share

Source: https://habr.com/ru/post/1684292/


All Articles