Announcing ‘Woof’, a pure Scala 3 logging library

Felix Bjært Hargreaves
Engineers @ The LEGO Group
3 min readDec 16, 2021

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.

What does it look like?

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.

How does it work?

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.

Does it work with … ?

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!).

What now?

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.

Q&A

  • 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

--

--

Felix Bjært Hargreaves
Engineers @ The LEGO Group

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