I’d like to write a logger trait that will log a specific set of events (e.g. create job, log progress, get jobs). Implementations will log to stdout / some file / postgres, etc.
My question is how best to implement multiple threads submitting logging requests. An mpsc::channel
seems like the right way, but since there are multiple event types (with different payloads), I’d end up either with a receiver for each message type, or implementing a protocol over single channel.
The other options seems to be to use mutexes / Arc’s and functions defined on the trait for each event type.
Is there another approach that would be more idiomatic?