mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"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
|
|
|
|
func initAppConfig() {
|
|
cfg, err := config.LoadConfigFromFile(viper.GetViper(), &cliOpts)
|
|
if err != nil {
|
|
fmt.Printf("failed to load application config: \n\t%+v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
appConfig = cfg
|
|
}
|
|
|
|
func initLogging() {
|
|
config := logger.LogConfig{
|
|
EnableConsole: (appConfig.Log.FileLocation == "" || appConfig.CliOptions.Verbosity > 0) && !appConfig.Quiet,
|
|
EnableFile: appConfig.Log.FileLocation != "",
|
|
Level: appConfig.Log.LevelOpt,
|
|
Structured: appConfig.Log.Structured,
|
|
FileLocation: appConfig.Log.FileLocation,
|
|
}
|
|
|
|
imgbom.SetLogger(logger.NewZapLogger(config))
|
|
}
|
|
|
|
func logAppConfig() {
|
|
appCfgStr, err := yaml.Marshal(&appConfig)
|
|
|
|
if err != nil {
|
|
log.Debugf("Could not display application config: %+v", err)
|
|
} else {
|
|
log.Debugf("Application config:\n%+v", format.Magenta.Format(string(appCfgStr)))
|
|
}
|
|
}
|