29 lines
740 B
Go
29 lines
740 B
Go
package cli
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/logging"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// SetupInitialLogging starts logging to the terminal, at the level set by
|
|
// cmd's --quiet and --debug flags (--debug wins), before any configuration
|
|
// is loaded.
|
|
func SetupInitialLogging(cmd *cobra.Command) {
|
|
// Start logging to terminal first - any commands that want to use file
|
|
// logging should activate it themselves
|
|
logging.LogToTerminal()
|
|
|
|
// Check for quiet flag
|
|
if quiet, _ := cmd.Flags().GetBool("quiet"); quiet {
|
|
logging.SetLevel(slog.LevelError)
|
|
}
|
|
|
|
// Check for debug logging enabled (overrides quiet flag)
|
|
debugEnabled, _ := cmd.Flags().GetBool("debug")
|
|
if debugEnabled {
|
|
logging.EnableDebug()
|
|
}
|
|
}
|