Use zerolog for logging #771
Add proper logging to the desktop client. Splitted from !172 (closed)
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
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 (merged)) -
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