MCPcopy Index your code
hub / github.com/docker/docker-agent / setupLogging

Method setupLogging

cmd/root/root.go:288–305  ·  view source on GitHub ↗

setupLogging configures slog logging behavior. When --debug is enabled, logs are written to a rotating file /cagent.debug.log, or to the file specified by --log-file. Log files are rotated when they exceed 10MB, keeping up to 3 backup files.

()

Source from the content-addressed store, hash-verified

286// or to the file specified by --log-file. Log files are rotated when they exceed 10MB,
287// keeping up to 3 backup files.
288func (f *rootFlags) setupLogging() error {
289 if !f.debugMode {
290 slog.SetDefault(slog.New(slog.DiscardHandler))
291 return nil
292 }
293
294 path := cmp.Or(strings.TrimSpace(f.logFilePath), filepath.Join(paths.GetDataDir(), "cagent.debug.log"))
295
296 logFile, err := logging.NewRotatingFile(path)
297 if err != nil {
298 return err
299 }
300 f.logFile = logFile
301
302 slog.SetDefault(slog.New(slog.NewTextHandler(logFile, &slog.HandlerOptions{Level: slog.LevelDebug})))
303
304 return nil
305}
306
307// RuntimeError wraps runtime errors to distinguish them from usage errors
308type RuntimeError struct {

Callers 1

NewRootCmdFunction · 0.95

Calls 3

GetDataDirFunction · 0.92
NewRotatingFileFunction · 0.92
NewMethod · 0.45

Tested by

no test coverage detected