mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #7796 from skepticfx:fix-gvisor-7795
PiperOrigin-RevId: 462248229
This commit is contained in:
+11
-4
@@ -24,6 +24,7 @@ package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
@@ -162,10 +163,8 @@ type logContext struct {
|
||||
}
|
||||
|
||||
// bgContext is the context returned by context.Background.
|
||||
var bgContext Context = &logContext{
|
||||
Context: context.Background(),
|
||||
Logger: log.Log(),
|
||||
}
|
||||
var bgContext Context
|
||||
var bgOnce sync.Once
|
||||
|
||||
// Background returns an empty context using the default logger.
|
||||
// Generally, one should use the Task as their context when available, or avoid
|
||||
@@ -173,7 +172,15 @@ var bgContext Context = &logContext{
|
||||
//
|
||||
// Using a Background context for tests is fine, as long as no values are
|
||||
// needed from the context in the tested code paths.
|
||||
//
|
||||
// The global log.SetTarget() must be called before context.Background()
|
||||
func Background() Context {
|
||||
bgOnce.Do(func() {
|
||||
bgContext = &logContext{
|
||||
Context: context.Background(),
|
||||
Logger: log.Log(),
|
||||
}
|
||||
})
|
||||
return bgContext
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +260,8 @@ func Log() *BasicLogger {
|
||||
//
|
||||
// This is not thread safe and shouldn't be called concurrently with any
|
||||
// logging calls.
|
||||
//
|
||||
// SetTarget should be called before any instances of log.Log() to avoid race conditions
|
||||
func SetTarget(target Emitter) {
|
||||
logMu.Lock()
|
||||
defer logMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user