userLogEmitter returns an emitter to add logs to user logs if requested.
(conf *config.Config, subcommand string)
| 335 | |
| 336 | // userLogEmitter returns an emitter to add logs to user logs if requested. |
| 337 | func 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 | |
| 365 | type bufferedLog struct { |
| 366 | depth int |