kazu-yamamoto/logger

WriterLoggerT data type

Closed this issue · 8 comments

Is it possible to implement a WriterLoggerT with a corresponding MonadLogger instance to runWriterLoggerT and get a list of log messages? This would be useful for our testing, without having to resort to a channel.

We're trying this at the moment. Would you like an informal PR with a sketch of the code that you could tweak to make it production ready? (we might not have the experience to do this properly yet).

And thanks for replying so fast :-)!

Sure, that sounds good. There's an interesting question here about whether a pure WriterT should be used, or an IORef holding it. Also, I'd recommend using a difference list for cheap append, e.g., instead of [LogMessage], use [LogMessage] -> [LogMessage].

Cool, we just finished the code, I can do a PR tomorrow. I guess it's better to roll my own difference list locally, just for appending, and not add another dependency to dlist, right?

Also about a pure WriterT our use case is really unit testing, what would an IORef bring? And in that case why not use the existing channel support?

Yeah, I'd avoid the dlist dependency.

Using the IORef approach would mean that the transformer remains isomorphic to ReaderT, which brings a bunch of benefits in the monad transformer world. For example, it would allow multi-threaded support and using MonadUnliftIO. I honestly forgot we had the channel support in the library, it's probably pretty similar.

The new repo of monad-logger is https://github.com/snoyberg/monad-logger
I would like to close this.