ronantakizawa/codereview-bench huggingface dataset:
Repository: grpc/grpc-go
File: internal/grpcsync/event.go (Go)

Code before:
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// Package grpcsync implements additional synchronization primitives built upon
// the sync package.
package grpcsync

import (
	"sync/atomic"
)

// Event represents a one-time event that may occur in the future.
type Event struct {
	fired atomic.Bool
	c     chan struct{}
}

// Fire causes e to complete.  It is safe to call multiple times, and
// concurrently.  It returns true iff this call to Fire caused the signaling
// channel returned by Done to close.
func (e *Event) Fire() bool {
	if e.fired.CompareAndSwap(false, true) {
		close(e.c)
		return true
	}
	return false
}

// Done returns a channel that will be closed when Fire is called.
func (e *Event) Done() <-chan struct{} {
	return e.c
}

// HasFired returns true if Fire has been called.
func (e *Event) HasFired() bool {
	return e.fired.Load()
}

// NewEvent returns a new, ready-to-use Event.
func NewEvent() *Event {
	return &Event{c: make(chan struct{})}
}


Review comment (suggestion):
Now that I think about it, we should maybe document the new behavior as a detail:

```suggestion
// Fire causes e to complete.  It is safe to call multiple times, and
// concurrently.  It returns true iff this call to Fire caused the signaling
// channel returned by Done to close. If Fire returns false, it is possible
// the Done channel has not been closed yet.
```

Code after:
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// Package grpcsync implements additional synchronization primitives built upon
// the sync package.
package grpcsync

import (
	"sync/atomic"
)

// Event represents a one-time event that may occur in the future.
type Event struct {
	fired atomic.Bool
	c     chan struct{}
}

// Fire causes e to complete.  It is safe to call multiple times, and
// concurrently.  It returns true iff this call to Fire caused the signaling
// channel returned by Done to close. If Fire returns false, it is possible
// the Done channel has not been closed yet.
func (e *Event) Fire() bool {
	if e.fired.CompareAndSwap(false, true) {
		close(e.c)
		return true
	}
	return false
}

// Done returns a channel that will be closed when Fire is called.
func (e *Event) Done() <-chan struct{} {
	return e.c
}

// HasFired returns true if Fire has been called.
func (e *Event) HasFired() bool {
	return e.fired.Load()
}

// NewEvent returns a new, ready-to-use Event.
func NewEvent() *Event {
	return &Event{c: make(chan struct{})}
}
Repository: grpc/grpc-go
File: internal/leakcheck/leakcheck_test.go (Go)

Code before:
	"fmt"
	"strings"
	"sync"
	"testing"
	"time"

	"google.golang.org/grpc/internal"
)

type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	for i := 0; i < leakCount; i++ {
		go func() { time.Sleep(2 * time.Second) }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines found %v leaks, want %v leaks", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount == 0 {
		t.Errorf("CheckGoroutines found %v leaks, want %v leaks", e.errorCount, leakCount)
	}
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	const leakCount = 3
	for i := 0; i < leakCount; i++ {
		go func() { time.Sleep(2 * time.Second) }()
	}

Review comment (suggestion):
Can you change this to not use `Sleep`?  We should always avoid sleeps for correctness.

Instead do:

```go
ch := make(chan struct{})
for i := 0; i < leakCount; i++ {
	go func() { <-ch }()
}

// test interestingGoroutines() and CheckGoroutines()

close(ch) // make goroutines exit
```


Code after:
	"fmt"
	"strings"
	"sync"
	"testing"
	"time"

	"google.golang.org/grpc/internal"
)

type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines() = %d, want length %d", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount < leakCount {
		t.Errorf("CheckGoroutines() = %d, want count %d", e.errorCount, leakCount)
		t.Logf("leaked goroutines:\n%v", strings.Join(e.errors, "\n"))
	}
	close(ch)
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	go ignoredTestingLeak(3 * time.Second)
Repository: grpc/grpc-go
File: internal/leakcheck/leakcheck_test.go (Go)

Code before:
	"time"

	"google.golang.org/grpc/internal"
)

type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines found %v leaks, want %v leaks", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount < 3 {
		t.Errorf("CheckGoroutines found %v leaks, want %v leaks", e.errorCount, leakCount)
	}
	close(ch)
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {

Review comment (suggestion):
Go style:

```suggestion
		t.Errorf("interestingGoroutines() = %v; want length %v", leaked, leakCount)
```

Code after:
	"time"

	"google.golang.org/grpc/internal"
)

type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines() = %d, want length %d", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount < leakCount {
		t.Errorf("CheckGoroutines() = %d, want count %d", e.errorCount, leakCount)
		t.Logf("leaked goroutines:\n%v", strings.Join(e.errors, "\n"))
	}
	close(ch)
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	go ignoredTestingLeak(3 * time.Second)
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
Repository: grpc/grpc-go
File: internal/leakcheck/leakcheck_test.go (Go)

Code before:
type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines found %v leaks, want %v leaks", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount < 3 {
		t.Errorf("CheckGoroutines found %v leaks, want %v leaks", e.errorCount, leakCount)
	}
	close(ch)
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines found %v leaks, want %v leaks", len(leaked), leakCount)
	}
	go func() { ignoredTestingLeak(3 * time.Second) }()
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)

Review comment (suggestion):
You should use `leakCount` again instead of copying.

Code after:
type testLogger struct {
	errorCount int
	errors     []string
}

func (e *testLogger) Logf(string, ...any) {
}

func (e *testLogger) Errorf(format string, args ...any) {
	e.errors = append(e.errors, fmt.Sprintf(format, args...))
	e.errorCount++
}

func TestCheck(t *testing.T) {
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines() = %d, want length %d", len(leaked), leakCount)
	}
	e := &testLogger{}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	if CheckGoroutines(ctx, e); e.errorCount < leakCount {
		t.Errorf("CheckGoroutines() = %d, want count %d", e.errorCount, leakCount)
		t.Logf("leaked goroutines:\n%v", strings.Join(e.errors, "\n"))
	}
	close(ch)
	ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	CheckGoroutines(ctx, t)
}

func ignoredTestingLeak(d time.Duration) {
	time.Sleep(d)
}

func TestCheckRegisterIgnore(t *testing.T) {
	RegisterIgnoreGoroutine("ignoredTestingLeak")
	go ignoredTestingLeak(3 * time.Second)
	const leakCount = 3
	ch := make(chan struct{})
	for i := 0; i < leakCount; i++ {
		go func() { <-ch }()
	}
	if leaked := interestingGoroutines(); len(leaked) != leakCount {
		t.Errorf("interestingGoroutines() = %d, want length %d", len(leaked), leakCount)
	}
	e := &testLogger{}
Repository: grpc/grpc-go
File: credentials/tls/certprovider/pemfile/watcher_test.go (Go)

Code before:
}

func compareKeyMaterial(got, want *certprovider.KeyMaterial) error {
	if len(got.Certs) != len(want.Certs) {
		return fmt.Errorf("keyMaterial certs = %+v, want %+v", got, want)
	}
	for i := 0; i < len(got.Certs); i++ {
		if !got.Certs[i].Leaf.Equal(want.Certs[i].Leaf) {
			return fmt.Errorf("keyMaterial certs = %+v, want %+v", got, want)
		}
	}

	if gotR, wantR := got.Roots, want.Roots; !gotR.Equal(wantR) {
		return fmt.Errorf("keyMaterial roots = %v, want %v", gotR, wantR)
	}

	if gotBundle, wantBundle := got.SPIFFEBundleMap, want.SPIFFEBundleMap; !cmp.Equal(gotBundle, wantBundle) {
		return fmt.Errorf("keyMaterial spiffe bundle map = %v, want %v", gotBundle, wantBundle)
	}

	return nil
}

// TestNewProvider tests the NewProvider() function with different inputs.
func (s) TestNewProvider(t *testing.T) {
	testutils.SetEnvConfig(t, &envconfig.XDSSpiffeEnabled, true)
	tests := []struct {
		desc      string
		options   Options
		wantError bool
	}{
		{
			desc:      "No credential files specified",
			options:   Options{},
			wantError: true,
		},
		{
			desc: "Only identity cert is specified",
			options: Options{
				CertFile: testdata.Path("x509/client1_cert.pem"),
			},
			wantError: true,
		},
		{
			desc: "Only identity key is specified",
			options: Options{
				KeyFile: testdata.Path("x509/client1_key.pem"),
			},
			wantError: true,
		},
		{

Review comment (suggestion):
We also need a test case where the env var is set to `false`, but the bootstrap field is set, and we verify that the SPIFFE bundle is not used.

Code after:

func compareKeyMaterial(got, want *certprovider.KeyMaterial) error {
	if len(got.Certs) != len(want.Certs) {
		return fmt.Errorf("keyMaterial certs = %+v, want %+v", got, want)
	}
	for i := 0; i < len(got.Certs); i++ {
		if !got.Certs[i].Leaf.Equal(want.Certs[i].Leaf) {
			return fmt.Errorf("keyMaterial certs = %+v, want %+v", got, want)
		}
	}

	if gotR, wantR := got.Roots, want.Roots; !gotR.Equal(wantR) {
		return fmt.Errorf("keyMaterial roots = %v, want %v", gotR, wantR)
	}

	if gotBundle, wantBundle := got.SPIFFEBundleMap, want.SPIFFEBundleMap; !cmp.Equal(gotBundle, wantBundle) {
		return fmt.Errorf("keyMaterial spiffe bundle map = %v, want %v", gotBundle, wantBundle)
	}

	return nil
}

// TestNewProvider tests the NewProvider() function with different inputs.
func (s) TestNewProvider(t *testing.T) {
	tests := []struct {
		desc      string
		options   Options
		wantError bool
	}{
		{
			desc:      "No credential files specified",
			options:   Options{},
			wantError: true,
		},
		{
			desc: "Only identity cert is specified",
			options: Options{
				CertFile: testdata.Path("x509/client1_cert.pem"),
			},
			wantError: true,
		},
		{
			desc: "Only identity key is specified",
			options: Options{
				KeyFile: testdata.Path("x509/client1_key.pem"),
			},
			wantError: true,
		},
		{
			desc: "Identity cert/key pair is specified",
			options: Options{
Repository: grpc/grpc-go
File: mem/buffer_slice.go (Go)

Code before:
	// calls to Read will return (0, io.EOF).
	Close() error
	// Remaining returns the number of unread bytes remaining in the slice.
	Remaining() int
	// Reset frees the currently held buffer slice and starts reading from the
	// provided slice. This allows reusing the reader object.
	Reset(s BufferSlice)
}

type sliceReader struct {
	data BufferSlice
	len  int
	// The index into data[0].ReadOnlyData().
	bufferIdx int
}

func (r *sliceReader) Remaining() int {
	return r.len
}

func (r *sliceReader) Reset(s BufferSlice) {
	r.Close()
	s.Ref()
	r.data = s
	r.len = s.Len()
	r.bufferIdx = 0
}

func (r *sliceReader) Close() error {
	r.data.Free()
	r.data = nil
	r.len = 0
	return nil
}

func (r *sliceReader) freeFirstBufferIfEmpty() bool {
	if len(r.data) == 0 || r.bufferIdx != len(r.data[0].ReadOnlyData()) {
		return false
	}

	r.data[0].Free()
	r.data = r.data[1:]
	r.bufferIdx = 0
	return true
}

func (r *sliceReader) Read(buf []byte) (n int, _ error) {
	if r.len == 0 {
		return 0, io.EOF
	}


Review comment (performance):
You could optimize very slightly by not calling `r.Close()` and just calling `r.data.Free()` instead, since you are initializing every field here.

But...that makes me wonder: why does `Close` bother clearing `data` and `len` in the first place?  I am thinking that's done intentionally "in case a read happens after `Close`".  If so, then are we sure it is okay to re-use them?

cc @PapaCharlie in case he remembers the motivation for this and can comment on the feasibility about reusing the readers here.

Code after:
	// calls to Read will return (0, io.EOF).
	Close() error
	// Remaining returns the number of unread bytes remaining in the slice.
	Remaining() int
	// Reset frees the currently held buffer slice and starts reading from the
	// provided slice. This allows reusing the reader object.
	Reset(s BufferSlice)
}

type sliceReader struct {
	data BufferSlice
	len  int
	// The index into data[0].ReadOnlyData().
	bufferIdx int
}

func (r *sliceReader) Remaining() int {
	return r.len
}

func (r *sliceReader) Reset(s BufferSlice) {
	r.data.Free()
	s.Ref()
	r.data = s
	r.len = s.Len()
	r.bufferIdx = 0
}

func (r *sliceReader) Close() error {
	r.data.Free()
	r.data = nil
	r.len = 0
	return nil
}

func (r *sliceReader) freeFirstBufferIfEmpty() bool {
	if len(r.data) == 0 || r.bufferIdx != len(r.data[0].ReadOnlyData()) {
		return false
	}

	r.data[0].Free()
	r.data = r.data[1:]
	r.bufferIdx = 0
	return true
}

func (r *sliceReader) Read(buf []byte) (n int, _ error) {
	if r.len == 0 {
		return 0, io.EOF
	}
Repository: grpc/grpc-go
File: internal/grpctest/tlogger.go (Go)

Code before:
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package grpctest

import (
	"errors"
	"fmt"
	"os"
	"path"
	"regexp"
	"runtime"
	"strconv"
	"sync"
	"sync/atomic"
	"testing"
	"time"

	"google.golang.org/grpc/grpclog"
)

// tLoggerAtomic serves as the grpclog logger and is the interface through which
// expected errors are declared in tests.
var tLoggerAtomic atomic.Value

const callingFrame = 4

type logType int

func (l logType) String() string {
	switch l {
	case infoLog:
		return "INFO"
	case warningLog:
		return "WARNING"
	case errorLog:
		return "ERROR"
	case fatalLog:
		return "FATAL"
	}
	return "UNKNOWN"
}

const (
	infoLog logType = iota
	warningLog
	errorLog
	fatalLog
)

Review comment (bug):
@easwars, the logger is mutated only once, in the `init()` function of this package. The race usually happens in the `Update` method (e.g: [b/416700146#comment4](http://b/416700146#comment4)) when it calls grpclog.SetLoggerV2:
https://github.com/grpc/grpc-go/blob/6dfe07c8c3e44c50dd7821626de1d73ed44bc455/grpclog/loggerv2.go#L35-L41
Ideally `Update` should be called serially at the beginning of a test function. I've seen race conditions reported when a test doesn't wait for its goroutines to return before the test function exits. Using an atomic for `LoggerV2Impl` and `DepthLoggerV2Impl` might hide those errors and make it appear as though the next test has logged something. Do you think we should really change this to use an atomic?

Code after:
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package grpctest

import (
	"errors"
	"fmt"
	"os"
	"path"
	"regexp"
	"runtime"
	"strconv"
	"sync"
	"testing"
	"time"

	"google.golang.org/grpc/grpclog"
)

// tLogr serves as the grpclog logger and is the interface through which
// expected errors are declared in tests.
var tLogr *tLogger

const callingFrame = 4

type logType int

func (l logType) String() string {
	switch l {
	case infoLog:
		return "INFO"
	case warningLog:
		return "WARNING"
	case errorLog:
		return "ERROR"
	case fatalLog:
		return "FATAL"
	}
	return "UNKNOWN"
}

const (
	infoLog logType = iota
	warningLog
	errorLog
	fatalLog
)
Repository: grpc/grpc-go
File: internal/grpctest/tlogger.go (Go)

Code before:
	}
	return "UNKNOWN"
}

const (
	infoLog logType = iota
	warningLog
	errorLog
	fatalLog
)

type tLogger struct {
	v           int
	initialized bool

	mu     sync.Mutex // guards t, start, and errors
	t      *testing.T
	start  time.Time
	errors map[*regexp.Regexp]int
}

func init() {
	tLoggerAtomic.Store(&tLogger{errors: map[*regexp.Regexp]int{}})
	vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL")
	if vl, err := strconv.Atoi(vLevel); err == nil {
		if logger, ok := tLoggerAtomic.Load().(*tLogger); ok {
			logger.v = vl
		}
	}
}

// getLogger returns the current logger instance.
func getLogger() *tLogger {
	return tLoggerAtomic.Load().(*tLogger)
}

// getCallingPrefix returns the <file:line> at the given depth from the stack.
func getCallingPrefix(depth int) (string, error) {
	_, file, line, ok := runtime.Caller(depth)
	if !ok {
		return "", errors.New("frame request out-of-bounds")
	}
	return fmt.Sprintf("%s:%d", path.Base(file), line), nil
}

// log logs the message with the specified parameters to the tLogger.
func (tl *tLogger) log(ltype logType, depth int, format string, args ...any) {
	tl.mu.Lock()
	defer tl.mu.Unlock()
	prefix, err := getCallingPrefix(callingFrame + depth)
	if err != nil {

Review comment (suggestion):
It's okay to use the infallible type assertion here since we're sure of the type.
```go
logger := tLoggerAtomic.Load().(*tLogger)
```

After reading further, we can use `getLogger` here.

Code after:
	return "UNKNOWN"
}

const (
	infoLog logType = iota
	warningLog
	errorLog
	fatalLog
)

type tLogger struct {
	v           int
	initialized bool

	mu     sync.Mutex // guards t, start, and errors
	t      *testing.T
	start  time.Time
	errors map[*regexp.Regexp]int
}

func init() {
	vLevel := 0 // Default verbosity level

	if vLevelEnv, found := os.LookupEnv("GRPC_GO_LOG_VERBOSITY_LEVEL"); found {
		// If found, attempt to convert. If conversion is successful, update vLevel.
		// If conversion fails, log a warning, but vLevel remains its default of 0.
		if val, err := strconv.Atoi(vLevelEnv); err == nil {
			vLevel = val
		} else {
			// Log the error if the environment variable is not a valid integer.
			fmt.Printf("Warning: GRPC_GO_LOG_VERBOSITY_LEVEL environment variable '%s' is not a valid integer. "+
				"Using default verbosity level 0. Error: %v\n", vLevelEnv, err)
		}
	}
	// Initialize tLogr with the determined verbosity level.
	tLogr = &tLogger{errors: make(map[*regexp.Regexp]int), v: vLevel}
}

// getCallingPrefix returns the <file:line> at the given depth from the stack.
func getCallingPrefix(depth int) (string, error) {
	_, file, line, ok := runtime.Caller(depth)
	if !ok {
		return "", errors.New("frame request out-of-bounds")
	}
	return fmt.Sprintf("%s:%d", path.Base(file), line), nil
}

// log logs the message with the specified parameters to the tLogger.
func (tl *tLogger) log(ltype logType, depth int, format string, args ...any) {
	tl.mu.Lock()
	defer tl.mu.Unlock()