Skip to content

Implement the slog.LogValuer interface #64

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

Merged
merged 3 commits into from
May 21, 2025
Merged

Implement the slog.LogValuer interface #64

merged 3 commits into from
May 21, 2025

Conversation

mbark
Copy link
Contributor

@mbark mbark commented May 15, 2025

When going through some logging inconsistencies locally I noticed that oops doesn't actually implement the LogValuer interface. Instead slog uses json.Marshal when logging (if you're logging as json).

The interface is defined as follows:

type LogValuer interface {
	LogValue() [Value](https://pkg.go.dev/log/slog#Value)
}

However, the implementation in oops is

func (o OopsError) LogValuer() slog.Value {
...
}

That is, the function is called LogValuer not LogValue!

This PR fixes this and also adds _ slog.LogValuer = (*OopsError)(nil) for clarity as well.

Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 75.54%. Comparing base (367f25c) to head (cae3ca8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
error.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
- Coverage   75.69%   75.54%   -0.15%     
==========================================
  Files          13       13              
  Lines        1049     1051       +2     
==========================================
  Hits          794      794              
- Misses        224      226       +2     
  Partials       31       31              
Flag Coverage Δ
unittests 75.54% <50.00%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber
Copy link
Owner

samber commented May 21, 2025

Thanks!

@samber samber merged commit 1bdea12 into samber:main May 21, 2025
7 of 9 checks passed
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