Skip to content

Add package level logging functions with DefaultLogger variable #136

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

Closed
wants to merge 1 commit into from

Conversation

ezzkoram
Copy link

Enables easy usage of a shared logger instance across different go packages.

DefaultLogger can be initialized in e.g. main package and slog.Info can be used anywhere in the system.

slog.DefaultLogger = slog.Make(sloghuman.Sink(os.Stdout))
slog.Info(ctx, "hello")

Loosely related to issue #82

There are two things that I'm not fully happy with:

  1. The slog.Error function is already in use so DefaultLogger.Error() is published as slog.Err(). Changing this would break the API
  2. Initialization of DefaultLogger is needed to have any output. There is no default sink created (as discussed in linked issue it would be a circular reference)

@ammario
Copy link
Member

ammario commented Mar 22, 2022

I'm closing this PR as it seems inactive.

@ammario ammario closed this Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants