Replies: 8 comments 13 replies
-
I really like the proposal and the POC! At $WORK, we ran into some problems similar to what you describe and also ended up writing our own interfaces on top. In our case, this also (but not exclusively) stems from the fact that we mostly use https://github.com/valskalla/odin for logging, but as TL libraries like http4s rely on log4cats, we can't avoid interacting with it. This leads to us bridging log4cats->slf4j->Odin. I would happily ditch this setup for a log4cats that has richer context structure, source code location and less coupling to slf4j. The design goals of the POC read sound, I agree with them. The code looks good at first glance (besides irrelevant nitpicks) and I like the fact there's a |
Beta Was this translation helpful? Give feedback.
-
So I really like the PoC, and the Fs2 backend is great. One caveat I will add though is that it's important to think through how to reduce allocations when certain log levels are disabled. It's kind of crappy that this is a problem worth thinking about, but it genuinely is (at least with |
Beta Was this translation helpful? Give feedback.
-
I dig this. You had me at SAMs and a JSON abstraction. |
Beta Was this translation helpful? Give feedback.
-
Thank you for putting this forward, I really like the proposal and the code. How would you do something like this with your proposed interface?
If I'm reading the code correctly it looks like |
Beta Was this translation helpful? Give feedback.
-
As one of the (absentee) maintainers of log4cats this proposal echoes very many things I have found lacking in log4cats but unable to muster the effort to bring them about. First, we must acknowledge that the interfaces we see log4cats were designed to make the fewest source code changes in order to stop doing side-effecty logs in Now, since I do not like the past to haunt me too much, could we embark on a road to make the interfaces in this proposal a log4cats
I am writing this up in a hurry, but I am definitely willing to put some effort into seeing this done somehow. And I started an enumeration because I expected the process to be much more difficult than this 😅 |
Beta Was this translation helpful? Give feedback.
-
@rossabaker, @iRevive, @ChristopherDavenport : hey folks, apologies for the ping, but I'd like your take on this, if you can spare the time. I think it's relevant to http4s / otel4s / the davenverse. |
Beta Was this translation helpful? Give feedback.
-
I like the proposal. At $work we primarily use https://github.com/valskalla/odin for logging, because the functionality can be extended in a matter of a few lines. With log4cats, in the current state, the situation may be different (e.g. #800). The POC looks good. I like the SAMs and Builder and how easy a middleware can be implemented. |
Beta Was this translation helpful? Give feedback.
-
I've taken a little time to wire my POC into http4s, see whether it could be done in a non-breaking way. Here it is, for the curious : Baccata/http4s#2 |
Beta Was this translation helpful? Give feedback.
-
Hello everyone
I've been meaning to write this down for a while, and it's not an easy topic to tackle, but I think it's one that deserves some more formalised discussion than an occasional quick rant in discord.
The point of this discussion
The thesis of this post is essentially that the interfaces offered by log4cats are not ideal for a number of reasons, and that using them as a defacto standard logging interfaces in the TL ecosystem is also not ideal, as it accidentally promotes an approach to logging that is vastly imperfect in Scala applications, both from a developer point of view, but also from an operator point of view. In effect, the current log4cats interfaces facilitate the leak of anti-patterns (in the context of FP) that are coming from Java-land.
My team at $work maintains Scala/Java tooling for numerous engineering teams of our organisation. We try to contribute to the open-source ecosystem in some ways, but a lot of what we work on is internal to the company. In particular, in the context of Scala, we maintain observability tooling for our users. This tooling that has tight integration with smithy4s and http4s, and essentially this takes the form of a "bootstrapping" construct that lowers the barrier of entry for having traced http-calls and logs correlated with the tracing information. For tracing, we've elected to expose the Natchez interface to our users (and are planning to explore the otel4s interface once it stabilises a bit). For logging however, even though the TL ecosystem provides a logging library in the form of log4cats, we've decided to ditch it in favour of a homegrown interface, which has surprised some of our users.
As the ecosystem expands, it pains me to see that the logging interface that the TL community has adopted as defacto standard suffers from the caveats that has led my team to create a homegrown thing, and motivates me to write a bit about it.
The POC
Instead of braindumping in the discussion, I've taken the time to describe the problems we see in the log4cats interface in this repo, and to expose a POC inspired from what we've done at $work but stripped out the coupling we've enforced :
https://github.com/Baccata/logger-poc/
In particular, the core of the POC is the LoggerKernel interface. What distinguishes from the log4cats interfaces are the following point :
Log
datatype directly, the single method takes a function of typeLog.Builder => Log.Builder
that allows to enrich such log data with bits of information. Because the user is not responsible for creating the log instance, it means that theLoggerKernel
implementations are free to decide upon how the data is stored in memory. The repo showcases aLog
implementation backed by a mutable data structures, thus having better control on the amount of allocationsLog.Builder
exposes a context capture method that leverages the visitor-pattern to capture (much) richer information than what aMap[String, String]
allows for, while still giving the control to implementors over if and how the data should be stored in intermediate data structures.Additionally to this
LoggerKernel
interface, the following POC elements are provided in this repo :LoggerKernel
, allowing for the capture of source-code information by means of the implicit macros provided by the sourcecode library, enriched with varargs-based methods that allow for capturing many bits of information without exponentially increasing the size of the interface.Channel
as a multiple-producer/single-consumer queue, and a more specialised one that prints logs to stdout in the background. Although the POC compiles against Scala 3.3.x on JVM, the code can be cross-compiled to all versions and all platforms supported by fs2.The goals
In my mind, the goal of this exercise would be the reaching of an acknowledgment that the current log4cats
Logger
andStructuredLogger
interfaces, as a central pillar to the TL ecosystem, are far from ideal, and that we could work towards improving the situation by providing better interfaces for application-developers and library-developers alike.Beta Was this translation helpful? Give feedback.
All reactions