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.
()
| 286 | // or to the file specified by --log-file. Log files are rotated when they exceed 10MB, |
| 287 | // keeping up to 3 backup files. |
| 288 | func (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 |
| 308 | type RuntimeError struct { |
no test coverage detected