mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/anchore/imgbom/imgbom"
|
|
"github.com/anchore/imgbom/internal/config"
|
|
"github.com/anchore/imgbom/internal/log"
|
|
"github.com/anchore/imgbom/internal/logger"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
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.Quiet,
|
|
EnableFile: appConfig.Log.FileLocation != "",
|
|
Level: appConfig.Log.LevelOpt,
|
|
FormatAsJSON: appConfig.Log.FormatAsJSON,
|
|
FileLocation: appConfig.Log.FileLocation,
|
|
}
|
|
|
|
imgbom.SetLogger(logger.NewZapLogger(config))
|
|
}
|
|
|
|
func logAppConfig() {
|
|
appCfgStr, err := json.MarshalIndent(&appConfig, " ", " ")
|
|
if err != nil {
|
|
log.Debugf("Could not display application config: %+v", err)
|
|
} else {
|
|
log.Debugf("Application config:\n%+v", string(appCfgStr))
|
|
}
|
|
}
|