Skip to content

grpclog: refactor existing logger interfaces for better interoparability #7431

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/grpclog/grpclog.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
os.Exit(1)
}

// V reports whether verbosity level l is at least the requested verbose level.
func V(l int) bool {
if DepthLogger != nil {
return DepthLogger.V(l)
} else {
return Logger.V(l)

Check warning on line 74 in internal/grpclog/grpclog.go

View check run for this annotation

Codecov / codecov/patch

internal/grpclog/grpclog.go#L74

Added line #L74 was not covered by tests
}
}

// LoggerV2 does underlying logging work for grpclog.
// This is a copy of the LoggerV2 defined in the external grpclog package. It
// is defined here to avoid a circular dependency.
Expand Down Expand Up @@ -123,4 +132,6 @@
ErrorDepth(depth int, args ...any)
// FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.
FatalDepth(depth int, args ...any)
// V reports whether verbosity level l is at least the requested verbose level.
V(l int) bool
}
8 changes: 4 additions & 4 deletions internal/grpclog/prefixLogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (pl *PrefixLogger) Errorf(format string, args ...any) {

// V reports whether verbosity level l is at least the requested verbose level.
func (pl *PrefixLogger) V(l int) bool {
// TODO(6044): Refactor interfaces LoggerV2 and DepthLogger, and maybe
// rewrite PrefixLogger a little to ensure that we don't use the global
// `Logger` here, and instead use the `logger` field.
return Logger.V(l)
if pl != nil {
return pl.logger.V(l)
}
return V(l)
}

// NewPrefixLogger creates a prefix logger with the given prefix.
Expand Down