mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 22:12:28 +01:00
add named logger + color formatting
This commit is contained in:
+1
-1
@@ -42,5 +42,5 @@ func setCliOptions() {
|
||||
fmt.Printf("unable to bind flag '%s': %+v", flag, err)
|
||||
}
|
||||
|
||||
rootCmd.Flags().CountVarP(&cliOpts.Verbosity, "verbose", "v", "increase verbosity (-v, -vv, -vvv ...)")
|
||||
rootCmd.Flags().CountVarP(&cliOpts.Verbosity, "verbose", "v", "increase verbosity (-v = info, -vv = debug)")
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,15 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/anchore/imgbom/imgbom"
|
||||
"github.com/anchore/imgbom/internal/config"
|
||||
"github.com/anchore/imgbom/internal/format"
|
||||
"github.com/anchore/imgbom/internal/log"
|
||||
"github.com/anchore/imgbom/internal/logger"
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var appConfig *config.Application
|
||||
@@ -25,10 +26,10 @@ func initAppConfig() {
|
||||
|
||||
func initLogging() {
|
||||
config := logger.LogConfig{
|
||||
EnableConsole: appConfig.Log.FileLocation == "" && !appConfig.Quiet,
|
||||
EnableConsole: (appConfig.Log.FileLocation == "" || appConfig.CliOptions.Verbosity > 0) && !appConfig.Quiet,
|
||||
EnableFile: appConfig.Log.FileLocation != "",
|
||||
Level: appConfig.Log.LevelOpt,
|
||||
FormatAsJSON: appConfig.Log.FormatAsJSON,
|
||||
Structured: appConfig.Log.Structured,
|
||||
FileLocation: appConfig.Log.FileLocation,
|
||||
}
|
||||
|
||||
@@ -36,10 +37,11 @@ func initLogging() {
|
||||
}
|
||||
|
||||
func logAppConfig() {
|
||||
appCfgStr, err := json.MarshalIndent(&appConfig, " ", " ")
|
||||
appCfgStr, err := yaml.Marshal(&appConfig)
|
||||
|
||||
if err != nil {
|
||||
log.Debugf("Could not display application config: %+v", err)
|
||||
} else {
|
||||
log.Debugf("Application config:\n%+v", string(appCfgStr))
|
||||
log.Debugf("Application config:\n%+v", format.Magenta.Format(string(appCfgStr)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user