Skip to content
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

Simplified logging middleware; Fields are now "any" type; Moved logging providers to examples only. #552

Merged
merged 1 commit into from Mar 30, 2023

Conversation

bwplotka
Copy link
Collaborator

Fixes #517

  • Simpler interface, only one method. This allows adapter to be ultra simple, so moved them to examples only (!).
  • Fields are string, values are any.
  • "More" slog compatibility.

I did not go for using slog natively as it's still experimental (see bigger discussion: https://gophers.slack.com/archives/C029RQSEE/p1679860885943619)

@bwplotka
Copy link
Collaborator Author

You might be interested in this @yashrsharma44 - I changed a lot the API, IMO for simpler. Let me know what you think! (:

@bwplotka bwplotka force-pushed the v2slog branch 2 times, most recently from eadbe9e to 0553e09 Compare March 30, 2023 13:59
…ng providers to examples only.

Fixes #517

* Simpler interface, only one method. This allows adapter to be ultra simple, so moved them to examples only (!).
* Fields are string, values are any.
* "More" slog compatibility.

I did not go for using slog natively as it's still experimental (see bigger discussion: https://gophers.slack.com/archives/C029RQSEE/p1679860885943619)

Signed-off-by: bwplotka <bwplotka@gmail.com>
Copy link
Collaborator

@yashrsharma44 yashrsharma44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a single question, apart from that, the changes looks good!

Thanks for working on this ❤️

return logging.LoggerFunc(func(_ context.Context, lvl logging.Level, msg string, fields ...any) {
largs := append([]any{"msg", msg}, fields...)
switch lvl {
case logging.LevelDebug:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use ERROR instead of introducing yet another enum for logging levels? Would be nice to have parity with logging conventions, for enums, instead of having yet another enum?

While it's understandable, I would still prefer using ERROR instead, unless there are some breaking changes in using the older convention :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ERROR? ERROR was replaced by LevelError and comon levels from slog there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I meant we were using logging.ERROR before, but if slog uses that - link, then let's use that convention.

// Second, we wanted to make it easy to use levels to specify logger verbosity.
// Since a larger level means a more severe event, a logger that accepts events
// with smaller (or more negative) level means a more verbose logger. Logger
// verbosity is thus the negation of event severity, and the default verbosity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should using "inverse" would be a better option? Negation implies that our definition is tied up in the implementation(we are negating in this case), however using inverse means that lower the log level(enum) included, more verbose our logging is, which is simple to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied all of this from slog, so there is less maintenance on our side (: So if you don't like this you can talk to slog authors 🙈 (https://pkg.go.dev/golang.org/x/exp/slog#pkg-overview)... I feel we can use whatever, so I thought we could use what others most likely start doing more.

// Logger requires Log method, similar to experimental slog, allowing logging interceptor to be interoperable. Official
// adapters for popular loggers are in `provider/` directory (separate modules). It's totally ok to copy simple function
// implementation over.
// TODO(bwplotka): Once slog is official, we could use slog method directly. Currently level is copied over, so we don't
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bwplotka bwplotka merged commit 8c53766 into v2 Mar 30, 2023
6 checks passed
@bwplotka bwplotka deleted the v2slog branch March 30, 2023 19:47
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.

None yet

2 participants