MCPcopy
hub / github.com/google/gvisor / userLogEmitter

Function userLogEmitter

runsc/cli/cli.go:337–363  ·  view source on GitHub ↗

userLogEmitter returns an emitter to add logs to user logs if requested.

(conf *config.Config, subcommand string)

Source from the content-addressed store, hash-verified

335
336// userLogEmitter returns an emitter to add logs to user logs if requested.
337func userLogEmitter(conf *config.Config, subcommand string) (log.Emitter, bool) {
338 if subcommand != "boot" || !conf.DebugToUserLog {
339 return nil, false
340 }
341 // We need to manually scan for `--user-log-fd` since it is a flag of the
342 // `boot` subcommand. We know it is in `--user-log-fd=FD` format because
343 // we control how arguments to `runsc boot` are formatted.
344 const userLogFDFlagPrefix = "--user-log-fd="
345 var userLog *os.File
346 for _, arg := range os.Args[1:] {
347 if !strings.HasPrefix(arg, userLogFDFlagPrefix) {
348 continue
349 }
350 if userLog != nil {
351 util.Fatalf("duplicate %q flag", userLogFDFlagPrefix)
352 }
353 userLogFD, err := strconv.Atoi(arg[len(userLogFDFlagPrefix):])
354 if err != nil {
355 util.Fatalf("invalid user log FD flag %q: %v", arg, err)
356 }
357 userLog = os.NewFile(uintptr(userLogFD), "user log file")
358 }
359 if userLog == nil {
360 return nil, false
361 }
362 return log.K8sJSONEmitter{&log.Writer{Next: userLog}}, true
363}
364
365type bufferedLog struct {
366 depth int

Callers 1

RunFunction · 0.85

Calls 2

FatalfFunction · 0.92
NewFileMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…