Add Verbose log level between Info and Debug

Implemented full log level hierarchy: Fatal, Error, Warn, Info, Verbose, Debug.
- Verbose level (-v) shows detailed operations like file changes (M/A/D)
- Debug level (-vv) shows low-level tracing with caller info
- Quiet mode (-q) sets level to Error, suppressing Info messages
- Banner and summary output now use log levels for filtering
This commit is contained in:
2025-12-17 15:17:27 -08:00
parent 0e86562c09
commit 5523cb1595
7 changed files with 187 additions and 92 deletions

View File

@@ -41,7 +41,7 @@ const banner = `
\__\/ \__\/ \__\/ \__\/`
func (mfa *CLIApp) printBanner() {
_, _ = fmt.Fprintln(mfa.Stdout, banner)
log.Info(banner)
}
// VersionString returns the version and git revision formatted for display.
@@ -49,10 +49,12 @@ func (mfa *CLIApp) VersionString() string {
return fmt.Sprintf("%s (%s)", mfa.version, mfa.gitrev)
}
func (mfa *CLIApp) setVerbosity(v int) {
func (mfa *CLIApp) setVerbosity(quiet bool, v int) {
_, present := os.LookupEnv("MFER_DEBUG")
if present {
log.EnableDebugLogging()
} else if quiet {
log.SetLevel(log.ErrorLevel)
} else {
log.SetLevelFromVerbosity(v)
}
@@ -98,10 +100,8 @@ func (mfa *CLIApp) run(args []string) {
Aliases: []string{"gen"},
Usage: "Generate manifest file",
Action: func(c *cli.Context) error {
if !c.Bool("quiet") {
mfa.printBanner()
}
mfa.setVerbosity(verbosity)
mfa.setVerbosity(c.Bool("quiet"), verbosity)
mfa.printBanner()
return mfa.generateManifestOperation(c)
},
Flags: []cli.Flag{
@@ -138,10 +138,8 @@ func (mfa *CLIApp) run(args []string) {
Usage: "Validate files using manifest file",
ArgsUsage: "[manifest file]",
Action: func(c *cli.Context) error {
if !c.Bool("quiet") {
mfa.printBanner()
}
mfa.setVerbosity(verbosity)
mfa.setVerbosity(c.Bool("quiet"), verbosity)
mfa.printBanner()
return mfa.checkManifestOperation(c)
},
Flags: []cli.Flag{
@@ -167,10 +165,8 @@ func (mfa *CLIApp) run(args []string) {
Usage: "Update manifest with changed, new, and removed files",
ArgsUsage: "[manifest file]",
Action: func(c *cli.Context) error {
if !c.Bool("quiet") {
mfa.printBanner()
}
mfa.setVerbosity(verbosity)
mfa.setVerbosity(c.Bool("quiet"), verbosity)
mfa.printBanner()
return mfa.freshenManifestOperation(c)
},
Flags: []cli.Flag{
@@ -209,10 +205,8 @@ func (mfa *CLIApp) run(args []string) {
Name: "fetch",
Usage: "fetch manifest and referenced files",
Action: func(c *cli.Context) error {
if !c.Bool("quiet") {
mfa.printBanner()
}
mfa.setVerbosity(verbosity)
mfa.setVerbosity(c.Bool("quiet"), verbosity)
mfa.printBanner()
return mfa.fetchManifestOperation(c)
},
},