Logger and Clean Architecture

This page summarizes the projects mentioned and recommended in the original post on reddit.com/r/golang

Our great sponsors
  • SonarQube - Static code analysis for 29 languages.
  • Scout APM - Less time debugging, more time building
  • SaaSHub - Software Alternatives and Reviews
  • zap

    Blazing fast, structured, leveled logging in Go.

    Hello Gophers, I read about Clean Architecture and I don't find anything regarding Logger which is sometime really nested in the code base. I really like https://github.com/uber-go/zap and even with a Logger interface I don't see how to keep things like the zap.String, zap.Int, etc. compatible with it. Is this a case where you have to compromise? Where you can compromise? Sometimes it is a reproach made to this type of architecture and the way people tend to stick to it too much, e.g., I can change the database but in fact it will probably never happen (but it will help for testing). Can it be the same with the Logger? Maybe I will create an interface with so much cohesion with Zap that it fact it is maybe better to assume that the project will use directly Zap?

  • logr

    A simple logging interface for Go

    I'd say it depends. If I write a package for others to use I usually don't include a logger at all and let the user decide what he wants to use. For any other project that needs logging I usually skip the interface to not have the struggle with finding one interface that fits all at least logrus and zap. We kinda agreed at the team to just use zap by now. One.thing i wanted to try tho is using sth like logr which provides an interface for the most commonly used loggers.

  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

  • life

    This is why we wrote https://github.com/go-logr/life - it's the interface you can pass around while leaving the choice of implementation up to the topmost app layer. We include some implementation choices (zapr being one, and funcr being among the simplest) but that's not really the goal.

  • go-core

    Something like this can help https://github.com/facily-tech/go-core/blob/main/log/interface.go

  • log15

    Structured, composable logging for Go

    This cracks me up: https://github.com/inconshreveable/log15 and I use log15 :)

  • go-logger

    A unified logging library with interchangeable backends (by InVisionApp)

    For that reason I would advise to use any logging aggregators that have rich adapters and capabilities to add new ones, eg. something like this: https://github.com/InVisionApp/go-logger . Note that this particular project is now abandoned (serious mem leak I posted as PR was never merged; I use my custom, public fork for that reason) so it is worth to ask: does anyone know about anything more recent, active and maintained that implements similar concept?

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts