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

fix slog source attribute #144

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

dai1975
Copy link
Contributor

@dai1975 dai1975 commented Jul 18, 2024

Problem:

RelayerLogger has wrapper functions to slog.log such as RelayerLogger.Error.
In case of application calls RelayerLogger.Error function, the source property of output log signs to RelayerLogger.Error function not caller of it.

Resolve

Passing upper of call stack to slog.
To perform it, I need to directly call slog.Handler().Handle(ctx, record) function.

others

Add test.
To simplify testing, I add writer paramerter to RelayerLog constructor.

@dai1975 dai1975 requested a review from a team as a code owner July 18, 2024 10:01
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

@dai1975 Generally good, but I left one comment.

func (rl *RelayLogger) Error(msg string, err error, otherArgs ...any) {
err = withstack.WithStackDepth(err, 1)
func (rl *RelayLogger) log(logLevel slog.Level, skipCallDepth int, msg string, args ...any) {
var pcs [1]uintptr
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to add the following?

if !l.Enabled(ctx, level) {
	return
}

Ref: https://github.com/golang/go/blob/go1.22.5/src/log/slog/logger.go#L242-L244

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. It is fixed.

Signed-off-by: Daisuke Kanda <[email protected]>
@dai1975 dai1975 force-pushed the features/fix-slog-source branch from cc7a240 to f5fa37d Compare July 22, 2024 04:36
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@siburu siburu merged commit cfa3a29 into hyperledger-labs:main Jul 22, 2024
6 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