4 ms·
so these are actually useful; below i link a fleshed out logger monad in a scala webapp. I wrote it because at work (enterprise webapps) we want to be able to s
by dustingetz 13y ago
so these are actually useful; below i link a fleshed out logger monad in a scala webapp. I wrote it because at work (enterprise webapps) we want to be able to send the logs created over the duration of a request down to the client for diagnostics. Singleton loggers (mutable globals) interleave the logs in a threaded context, and worse in async or high availability contexts, and are basically a giant pain in the ass to extract useful data from.
the actual monadic types are:
type MyLogger[+A] = WriterT[scalaz.Id.Id, List[String], A]
type IOLogger[V] = EitherT[MyLogger, Throwable, V]
which represents either an exception or a value, alongside the logs that led up to it.
https://github.com/dustingetz/monadic-logging-play/blob/master/app/controllers/Root.scala https://github.com/dustingetz/monadic-logging-play/blob/mast...
Forgive me if this code is ugly, this is my first foray into scalaz. The repo contains a complete minimum play app and will run. Also we're hiring in philadelphia.
- egonschiele 13y agoGlad you found the post useful!