Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Replace Zerolog with Go's slog #122

Open
dstpierre opened this issue May 17, 2024 · 2 comments
Open

Replace Zerolog with Go's slog #122

dstpierre opened this issue May 17, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@dstpierre
Copy link
Member

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 dstpierre added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels May 17, 2024
@dstpierre dstpierre added this to the v1.6 milestone May 17, 2024
@andrewtyw
Copy link

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

@dstpierre
Copy link
Member Author

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants