maybeAttachDebugFileSink reads KEPLOY_DEBUG_FILE and, if set, opens that path and attaches a debug-level file sink onto logger via the same in-place pointee mutation pattern the rest of the codebase uses for runtime logger swaps (see ChangeLogLevel / RedirectToStderr). Returns the opened file and si
(logger *zap.Logger)
| 256 | // All errors are non-fatal — if the file can't be opened (read-only mount, |
| 257 | // permission, etc.), the process continues with the original logger. |
| 258 | func maybeAttachDebugFileSink(logger *zap.Logger) (*os.File, *log.DebugFileSink) { |
| 259 | path := strings.TrimSpace(os.Getenv("KEPLOY_DEBUG_FILE")) |
| 260 | if path == "" { |
| 261 | return nil, nil |
| 262 | } |
| 263 | f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644) |
| 264 | if err != nil { |
| 265 | logger.Warn("KEPLOY_DEBUG_FILE set but could not be opened; continuing without debug capture", |
| 266 | zap.String("path", path), zap.Error(err)) |
| 267 | return nil, nil |
| 268 | } |
| 269 | wrapped, sink := log.AddDebugFileSink(logger, f, 100<<20) |
| 270 | if wrapped == nil || sink == nil { |
| 271 | _ = f.Close() |
| 272 | return nil, nil |
| 273 | } |
| 274 | *logger = *wrapped |
| 275 | // Publish the sink so cross-package helpers (e.g. the agent's |
| 276 | // per-test-set rotation in pkg/agent/routes) can reach it without |
| 277 | // threading the sink through every constructor. |
| 278 | log.SetDebugFileSink(sink) |
| 279 | logger.Debug("KEPLOY_DEBUG_FILE attached", zap.String("path", path)) |
| 280 | return f, sink |
| 281 | } |
| 282 | |
| 283 | // printEnterpriseUpgradeBanner emits a high-visibility nudge to install |
| 284 | // the Keploy Enterprise binary — entry plan is Community Edition (free) |
no test coverage detected