feat: capture cli logs in tests (#10669)

Adds a Logger to cli Invocation and standardizes CLI commands to use it.  clitest creates a test logger by default so that CLI command logs are captured in the test logs.

CLI commands that do their own log configuration are modified to add sinks to the existing logger, rather than create a new one.  This ensures we still capture logs in CLI tests.
This commit is contained in:
Spike Curtis
2023-11-14 22:56:27 +04:00
committed by GitHub
parent 90b6e86555
commit 4894eda711
15 changed files with 38 additions and 48 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ func (r *RootCmd) newCreateAdminUserCommand() *clibase.Cmd {
}
cfg := r.createConfig()
logger := slog.Make(sloghuman.Sink(inv.Stderr))
logger := inv.Logger.AppendSinks(sloghuman.Sink(inv.Stderr))
if r.verbose {
logger = logger.Leveled(slog.LevelDebug)
}