mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
add version to logs (#715)
This commit is contained in:
parent
b7979dbc7d
commit
474ed682bc
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
func checkForApplicationUpdate() {
|
func checkForApplicationUpdate() {
|
||||||
if appConfig.CheckForAppUpdate {
|
if appConfig.CheckForAppUpdate {
|
||||||
|
log.Debugf("checking if new vesion of %s is available", internal.ApplicationName)
|
||||||
isAvailable, newVersion, err := version.IsUpdateAvailable()
|
isAvailable, newVersion, err := version.IsUpdateAvailable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// this should never stop the application
|
// this should never stop the application
|
||||||
|
|||||||
38
cmd/cmd.go
38
cmd/cmd.go
@ -1,17 +1,19 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"github.com/anchore/stereoscope"
|
"github.com/anchore/stereoscope"
|
||||||
"github.com/anchore/syft/internal/config"
|
"github.com/anchore/syft/internal/config"
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
"github.com/anchore/syft/internal/logger"
|
"github.com/anchore/syft/internal/logger"
|
||||||
|
"github.com/anchore/syft/internal/version"
|
||||||
"github.com/anchore/syft/syft"
|
"github.com/anchore/syft/syft"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/wagoodman/go-partybus"
|
"github.com/wagoodman/go-partybus"
|
||||||
)
|
)
|
||||||
@ -28,6 +30,8 @@ func init() {
|
|||||||
initAppConfig,
|
initAppConfig,
|
||||||
initLogging,
|
initLogging,
|
||||||
logAppConfig,
|
logAppConfig,
|
||||||
|
checkForApplicationUpdate,
|
||||||
|
logAppVersion,
|
||||||
initEventBus,
|
initEventBus,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -110,3 +114,33 @@ func initEventBus() {
|
|||||||
stereoscope.SetBus(eventBus)
|
stereoscope.SetBus(eventBus)
|
||||||
syft.SetBus(eventBus)
|
syft.SetBus(eventBus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func logAppVersion() {
|
||||||
|
versionInfo := version.FromBuild()
|
||||||
|
log.Infof("syft version: %s", versionInfo.Version)
|
||||||
|
|
||||||
|
var fields map[string]interface{}
|
||||||
|
bytes, err := json.Marshal(versionInfo)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(bytes, &fields)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
keys := make([]string, 0, len(fields))
|
||||||
|
for k := range fields {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for idx, field := range keys {
|
||||||
|
value := fields[field]
|
||||||
|
branch := "├──"
|
||||||
|
if idx == len(fields)-1 {
|
||||||
|
branch = "└──"
|
||||||
|
}
|
||||||
|
log.Debugf(" %s %s: %s", branch, field, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -260,8 +260,6 @@ func packagesExecWorker(userInput string) <-chan error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForApplicationUpdate()
|
|
||||||
|
|
||||||
src, cleanup, err := source.New(userInput, appConfig.Registry.ToOptions(), appConfig.Exclusions)
|
src, cleanup, err := source.New(userInput, appConfig.Registry.ToOptions(), appConfig.Exclusions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- fmt.Errorf("failed to determine image source: %w", err)
|
errs <- fmt.Errorf("failed to determine image source: %w", err)
|
||||||
|
|||||||
@ -111,8 +111,6 @@ func powerUserExecWorker(userInput string) <-chan error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForApplicationUpdate()
|
|
||||||
|
|
||||||
src, cleanup, err := source.New(userInput, appConfig.Registry.ToOptions(), appConfig.Exclusions)
|
src, cleanup, err := source.New(userInput, appConfig.Registry.ToOptions(), appConfig.Exclusions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- err
|
errs <- err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user