Add slog and less verbose logging by default
This commit is contained in:
parent
a8d7407093
commit
50c46b1b6e
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module github.com/iamthefij/tag-notifier
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
git.iamthefij.com/iamthefij/slog v0.0.0-20201202020306-f6ae8b7d5a96
|
||||
github.com/containerd/containerd v1.4.3 // indirect
|
||||
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||
github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible
|
||||
|
2
go.sum
2
go.sum
@ -1,4 +1,6 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
git.iamthefij.com/iamthefij/slog v0.0.0-20201202020306-f6ae8b7d5a96 h1:uIr3Bz44Unzft7f2mUsYiF/wFB4lrCl82GUFfIlZCd4=
|
||||
git.iamthefij.com/iamthefij/slog v0.0.0-20201202020306-f6ae8b7d5a96/go.mod h1:1RUj4hcCompZkAxXCRfUX786tb3cM/Zpkn97dGfUfbg=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Microsoft/go-winio v0.4.15 h1:qkLXKzb1QoVatRyd/YlXZ/Kg0m5K3SPuoD82jjSOaBc=
|
||||
github.com/Microsoft/go-winio v0.4.15/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
|
||||
|
21
main.go
21
main.go
@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.iamthefij.com/iamthefij/slog"
|
||||
dockerTypes "github.com/docker/docker/api/types"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
)
|
||||
@ -184,9 +185,10 @@ func getNewerTags(current ImageTag) ([]ImageTag, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.StringVar(®istryBaseURL, "registry-url", registryBaseURL, "base url of the registry you want to check against")
|
||||
flag.StringVar(&defaultRegistryBaseURL, "registry-url", defaultRegistryBaseURL, "base url of the registry you want to check against")
|
||||
flag.IntVar(&maxPages, "max-pages", maxPages, "max number of pages to retrieve from registry")
|
||||
var showVersion = flag.Bool("version", false, "display the version and exit")
|
||||
flag.BoolVar(&slog.DebugLevel, "debug", false, "show debug logs")
|
||||
flag.Parse()
|
||||
|
||||
// Print version if asked
|
||||
@ -212,23 +214,24 @@ func main() {
|
||||
images[container.Image] = true
|
||||
}
|
||||
for image := range images {
|
||||
fmt.Printf("[%s] Checking for updates...\n", image)
|
||||
slog.Debug("[%s] Checking for updates...", image)
|
||||
it, err := ParseImageTag(image)
|
||||
if err != nil {
|
||||
fmt.Printf("[%s] Can't parse tag: %v\n", image, err)
|
||||
slog.Debug("[%s] Can't parse tag: %v", image, err)
|
||||
continue
|
||||
}
|
||||
newerTags, err := getNewerTags(it)
|
||||
if err != nil {
|
||||
fmt.Printf("[%s] Panic getting new tags: %v\n", image, err)
|
||||
panic(err)
|
||||
}
|
||||
slog.PanicOnErr(err, "[%s] failed getting new tags", image)
|
||||
if len(newerTags) == 0 {
|
||||
fmt.Printf("[%s] No newer versions found\n", image)
|
||||
slog.Debug("[%s] No newer versions found", image)
|
||||
continue
|
||||
}
|
||||
hasUpdate = true
|
||||
fmt.Printf("[%s] Newer version found. Recommend update to %s\n", image, newerTags[0].ImageTag)
|
||||
if slog.DebugLevel {
|
||||
slog.Info("[%s] Newer version found! Recommended update to %s", image, newerTags[0].ImageTag)
|
||||
} else {
|
||||
fmt.Printf("[%s] Newer version found! Recommended update to %s\n", image, newerTags[0].ImageTag)
|
||||
}
|
||||
}
|
||||
|
||||
if hasUpdate {
|
||||
|
Loading…
Reference in New Issue
Block a user