Announcing ‘Woof’, a pure Scala 3 logging library

At the LEGO Group, we have been discussing OSS for many years, especially looking for the best way to introduce ourselves into this space. We consider ourselves to be a strong digital player and of course this requires us to chip in, also when it comes to contribution and open sourcing code. As part of this journey, I am very happy to announce our open sourced Scala project — Woof.

Woof is a pure logging library for functional programming in Scala 3. As of today, it has only 2 dependencies: cats-core and cats-effect. The latter provides the functional effects used to defer logging to the IO runtime.

Using Woof looks like so:

Note that the logger is easily injected — some libraries require you to instantiate a logger for each class using it. This becomes problematic when you want to deal with e.g. logging contexts and injection. I believe the reason for instantiating specific instances per class is either ease of use, or performance related to reflection — the class name only needs to be resolved once per class instance.

Woof resolves class names and line numbers with Scala 3 macros used inside the debug, info, warn, and error calls. This approach allows us to inject the logger without any loss of performance or convenience which in turn allows us to add context to the logger from outside a class instance even before the instance is created.

While the above code example uses the IO type directly from cats-effect, we could also use the type classes in a tagless final style:

This is how we are using the library internally, and we’re pretty happy with this approach. Note also, that the code here is completely oblivious to any context or configuration given to the logger from the outside, allowing us to reuse and compose the program as needed.

Woof has interop modules for Slf4j as well as Http4s. If you work with Http4s, you might benefit from both, since it uses Slf4j under the hood. The Http4s support simply adds correlation ids for each request, which can be very convenient when looking through server logs.

Note that there are much more advanced tracing libraries out there, but for out of box support, we find that what we have with Woof is quite nice. If you have a multi-layered micro services architecture, you might find more use in a more advanced solution (which you can definitely also make work together with Woof!).

We are looking forward to listening to community feedback regarding feature requests, bug reports, etc. In the future, we will probably want to open up for pull requests from third parties. As of now, we will maintain and develop it in our team.

  • Can I try it out?
    — Yes, just head to https://github.com/LEGO/woof and follow the instructions
  • Can I make my own color theme for the logs?
    — Of course you can! Get inspired by the default theme here.
  • Do you mainly use Scala at The LEGO Group?
    — No, not at all. In our team, yes, but in general we have a rich eco system of mainly the usual suspects like TypeScript, JavaScript, C#, Swift, Java, Python etc.
  • Why is it called ‘Woof’?
    — It’s like the barking sound of a dog (i.e. the OUTPUT of a dog :D ). Also, we were inspired a bit by WUPHF.com from the American ‘The Office’.
  • Where can I get more news about OSS and The LEGO Group?
    — Follow @LEGOEngineering on Twitter or start “starring” our projects on https://github.com/LEGO

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Felix Bjært Hargreaves

Senior Engineer at the LEGO Group. Passionate functional programmer and Scala developer.