Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logging library for Go applications #1048

Assignees
Labels
enhancement New feature or request

Comments

@Richard87
Copy link
Contributor

Richard87 commented Sep 25, 2023

Change Go logging library in the following applications

Is your feature request related to a problem? Please describe.
Currently our logging library (logrus) is slow, and limited support for structured logging. This makes it overly hard to troubleshoot bugs.

Describe the solution you'd like
Start using structured logging

Describe alternatives you've considered
I think there are 4 relevant solutions:

  • Keep using logrus, but start using the structured output (slow)
  • Migrate to slog (new golang standard log library)
  • Migrate to zerolog (apparantly twice as fast as slog. Interresting, but very different logging API from slog and logrus)
  • Migrate to zerolog, but introduce our own interface matching slog/log (I assume this will be equall to or slower than slog)
  • Look into Zap, almost same performance as Zerolog, similar/same API as log/slog

Performance testing from Uber/Zap: https://github.com/uber-go/zap#performance
Log a message and 10 fields:

Package Time Time % to zap Objects Allocated
zerolog 380 ns/op -42% 1 allocs/op
zap 656 ns/op +0% 5 allocs/op
zap (sugared) 935 ns/op +43% 10 allocs/op
go-kit 2249 ns/op +243% 57 allocs/op
slog (LogAttrs) 2479 ns/op +278% 40 allocs/op
slog 2481 ns/op +278% 42 allocs/op
apex/log 9591 ns/op +1362% 63 allocs/op
log15 11393 ns/op +1637% 75 allocs/op
logrus 11654 ns/op +1677% 79 allocs/op

Zerolog:

log.Debug().
    Str("Scale", "833 cents").
    Float64("Interval", 833.09).
    Msg("Fibonacci is everywhere")

slog:

slog.Info("Fibonacci is everywhere", 
    "Scale", "833 cents"
    "Interval", 833,09,
    )

zap:

// Sugar log:
sugar.Infow("Fibonacci is everywhere",
  "Scale",  "833 cents"
  "Interval", 833,09,
  )

// Fastest:
logger.Info("Fibonacci is everywhere",
  zap.String("Scale",  "833 cents"),
  zap.Float6("Interval", 833,09),
  )

logrus

  log.WithFields(log.Fields{
    "Scale":    "833 cents",
    "Interval": 833,09,
  })
  .Info("Fibonacci is everywhere")
@Richard87 Richard87 added the enhancement New feature or request label Sep 25, 2023
@Richard87 Richard87 self-assigned this Sep 25, 2023
@Richard87 Richard87 added added to backlog Issue registered in our Product Backlog ready for evaluation and removed added to backlog Issue registered in our Product Backlog ready for evaluation labels Sep 25, 2023
@sondresjolyst
Copy link
Contributor

ref: equinor/radix-cicd-canary#175

@Richard87 Richard87 removed their assignment Oct 31, 2023
@Richard87 Richard87 linked a pull request Feb 26, 2024 that will close this issue
@Richard87 Richard87 reopened this Mar 1, 2024
@Richard87 Richard87 linked a pull request Mar 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment