Support structured logging
Closed this issue · 1 comments
Currently, the org.legogroup.Output
expects String
as input which would stop the application from efficiently doing any kind of structured logging.
Combining the Printer
and Output
concept would easily solve this with a method signature similar to:
def output(
epochMillis: EpochMillis,
level: LogLevel,
info: LogInfo,
message: String,
context: List[(String, String)],
): F[Unit]
however, this will lead to a less composable architecture. We could change the arguments to a case class:
case class LogLine(
epochMillis: EpochMillis,
level: LogLevel,
info: LogInfo,
message: String,
context: List[(String, String)],
)
which would make it much easier to pass around. I still think there's some merit to separating the stateless transformations from the effectful outputs, but it's not easy to pick a suitable input type for the Output
class methods.
Consider the following:
- The user wants to print human readable lines in color to the std output
- The user also wants to send structured output as json to a structured log server via the network
Here, it would be nice to allow pairing up printers and outputs which would basically solve this and many more cases.
On a final note, I do realize that we could simply change it to be 1 concept of LogLine => F[Unit]
and let the library users do their own function composition, but I feel like that may be a bit too unclear and not very intention-revealing. This solution will not force people to use String
as an intermediate format, though!
Thoughts are very welcome!