core icon indicating copy to clipboard operation
core copied to clipboard

Replace Zerolog with Go's slog

Open dstpierre opened this issue 1 year ago • 2 comments

Now that Go has its own structure logger, we can drop the dependency on Zerolog and use Go's slog instead.

I think the quikest way to do this is by removing all import of zerolog.

Might be a good opportunity to maybe get rid of all logger pass around and simply use the global slog after configuring it based on the environment variables already used to Zerolog.

Couple of pointer for this tasks:

  • Exploration / reflection on if we should continue to pass a logger around, as slog has a sharable global instance.
  • Removing the logger field on structure and function protytope and building / fixing issue seems a good way to do this.
  • Doing a global search for zerolog's logger type and either removing or changing type based on exploration results.

dstpierre avatar May 17 '24 13:05 dstpierre

slog does not provide the Fatal() method, which this repository relies on. However, since there are fewer than 10 usages of Fatal(), we can replace them with Error() followed by os.Exit(1). This change allows us to share slog globally. If this solution doesn't work, it seems we should extend slog with Fatal() and continue to pass a logger around.

BTW, I would like to work on this issue, could you assign it to me? @dstpierre

andrewtyw avatar May 20 '24 06:05 andrewtyw

@andrewtyw nice and thanks for your interests.

For the .Fatal I believe calling the slog.SetDefault(logger) replaces the normal log so we could replace those with log.Fatal.

If it's cleaner, we could have an exported function in the core/logger package, say FatalError that calls slog and os.Exit. That way we would have a central place to control what's happening when a Fatal is called.

It would be nice to have slog output nice log to the terminal and optionally write to a file based on env variable.

There's LogFilename in the config.AppConfig which can be used to indicate if the user wants to output to a file.

I'll assign the issue to you, feel free to open a PR and let me know if I can help with anything.

dstpierre avatar May 20 '24 09:05 dstpierre