Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logging): respect log levels for skipped files #102

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ config, see the "copywrite init" command.`,
// log prefix, e.g. logger.Println("[DEBUG] this is inferred as a debug log")
InferLevels: true,
})
// Redirect output to stdout to match the rest of the command output structure
// Ideally, we would differentiate inside the addlicense run, but in lieu of
// reworking the entire logging functionality there, this at least gets us
// consistency and fixes a race condition when using GitHub Action log groups
stdcliLogger.SetOutput(os.Stdout)

// WARNING: because of the way we redirect cliLogger to os.Stdout, anything
// prefixed with "[ERROR]" will not implicitly be written to stderr.
// However, we propagate errors upward from addlicense and then run a
// cobra.CheckErr on the return, which will indeed output to stderr and
// return a non-zero error code.

gha.StartGroup("The following files are missing headers:")
err := addlicense.Run(ignoredPatterns, "only", licenseData, "", verbose, plan, []string{"."}, stdcliLogger)
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func initLogger() {

hclog.Default().Named("cli")
cliLogger = hclog.New(&hclog.LoggerOptions{
Name: "cli",
Level: logLevel,
Color: hclog.AutoColor,
Name: "cli",
Level: logLevel,
Color: hclog.AutoColor,
Output: os.Stdout,
})
}