Module implementation_notes

Source
Expand description

Implementation notes

We build our logging in a few layers.

At the lowest level, there is a [Loggable] trait, for events which can accumulate and eventually be flushed; this combines with the RateLim structure, which is responsible for managing the decision of when to flush these [Loggable]s.

The role of RateLim is to decide when to flush the information in a Loggable, and to flush the Loggable as needed. The role of a Loggable is to accumulate information and to know how to flush that information as a log message when it is told to do so.

One layer up, there is LogState, which is used to to implement Loggable as used by log_ratelim!. It can remember the name of an activity, accumulate successes and failures, and remember an error and associated message.

The highest layer is the log_ratelim! macro, which uses RateLim and LogState to record successes and failures, and launch background tasks as needed.