Skip to content

Use zerolog for logging #771

Pea Nut requested to merge improve-logging into main

Add proper logging to the desktop client. Splitted from !172

Changes

Multiple log levels are supported and can be set via env variable (LOG_LEVEL)

  • trace (LOG_LEVEL=TRACE)
  • debug (LOG_LEVEL=DEBUG)
  • everything else: INFO

Logging is set up in pkg/config/logger.go. Bot logging facilities (log/zerolog) are configured to write logs to the log file (as before). Until we get rid of v3 (Bitmask3 struct and vpn/bonafide/*.go), we still use the old 'log' module.

To find things, that still use rg -g '!*bonafide*' -g '!*vendor*' -g '!*snowflake*' -g '!*legacy*' '"log"'

  • v3 stuff (Should we also move to zerolog... Don't want to touch it to be honest):
    • legacy: Bitmask3 stuff
    • bonafide: legacy network stuff that speaks with webvpn
  • snowflake: I would fix this if we start using it? Feel free to give feedback
  • some smaller tools/helper are using the default log, but that's fine for me
    • branding/templates/qtinstaller/osx-data/post-install.go
    • cmd/bitmaskd/main.go
    • pkg/config/version/genver/main.go

Comments/to discuss/TODOs

  • TODO: Update README
  • I can not build on Linux/Windows => please check
  • running golangci-lint run --path-prefix=./... --timeout=5m shows a lot of things to improve (that's a seperate issue) (Update: most of them are fixed in !186)
  • I like the output of zerolog, but the written log file itself is a line based, so not super easy to read (I used zerolog because it was used in bitmask-core)
  • Both logger (log and zerolog) append their logs to a single log file. Currently, the log file is never closed. I will look at it...
  • What do you think about the time format: 2024-04-23T15:53:10+02:00
  • There is also some qml logging printed to stderr: I don't like the big logs (the big json)
    • The go code now logs to stdout, so that I can redirect stderr to /dev/null

Some ideas about log levels

  • fatal: used for non-recoverable errors, terminates whole application (just used fatal if it was used before):
    • backend/auth.go -> generateAuthToken -> writeFileToDisk
    • pkg/backend/actions.go => startVPN
    • pkg/backend/api.go => RefreshContext
  • warn: an error occured, but we can continue/recover from that
  • info: a relevant information to the user/something happend
  • debug: useful for dev debugging/analyzing censored environment
  • trace: use to show which functions are called (can be nice for dev, e. g. "stop the openvpn" is called twice sometimes during teardown, also RefreshContext calls a lot of stuff in the background (toJson())
Edited by Pea Nut

Merge request reports