Skip to content

Commit

Permalink
Logger changes, use JSON formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
cguertin14 committed Mar 10, 2022
1 parent a2f2a98 commit ea37f55
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func update(cmd *cobra.Command, args []string) (err error) {
}

// init logger
ctxLogger := logger.Initialize(logger.Config{Level: "info"})
ctxLogger := logger.Initialize(logger.Config{
Level: "info",
Formatter: logger.ServiceFormatter,
})
ctx = context.WithValue(ctx, logger.CtxKey, ctxLogger)

// create business logic client here
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cguertin14/k3supdater
go 1.17

require (
github.com/cguertin14/logger v1.0.3
github.com/cguertin14/logger v1.0.6
github.com/golang/mock v1.6.0
github.com/google/go-github/v43 v43.0.0
github.com/spf13/cobra v1.3.0
Expand All @@ -29,7 +29,7 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ github.com/cguertin14/logger v1.0.1 h1:7KsOos8We3CEIWweA4p4X4M4xdEwDmCAy+ZEvfkt0
github.com/cguertin14/logger v1.0.1/go.mod h1:6+2dKtJwRCN9vNhOEpmU3Lqj9pjfSK+KASw41jZSNzE=
github.com/cguertin14/logger v1.0.3 h1:ScySEFxR3TtCfrtf1g9PA+iz1Eebek4Hz8NtgDE0h9U=
github.com/cguertin14/logger v1.0.3/go.mod h1:HL+/DPVELHq4pGsejTJctxjwwKlTJaE3O4bbdSzOK6k=
github.com/cguertin14/logger v1.0.4 h1:obaH60zndI0gWrXkx+LZV6RtbEUN1SlwXVtpnZRQqBk=
github.com/cguertin14/logger v1.0.4/go.mod h1:HL+/DPVELHq4pGsejTJctxjwwKlTJaE3O4bbdSzOK6k=
github.com/cguertin14/logger v1.0.5 h1:QsJzNRFb0OLqUrizF97YV50xYAjYO4XtUeuiimPf4eQ=
github.com/cguertin14/logger v1.0.5/go.mod h1:HL+/DPVELHq4pGsejTJctxjwwKlTJaE3O4bbdSzOK6k=
github.com/cguertin14/logger v1.0.6 h1:Pc+4um0QJpXSivKofBlJ471xhzVAr3Frn5wWPgN1oBU=
github.com/cguertin14/logger v1.0.6/go.mod h1:HL+/DPVELHq4pGsejTJctxjwwKlTJaE3O4bbdSzOK6k=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -564,6 +570,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+R
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7 h1:8IVLkfbr2cLhv0a/vKq4UFUcJym8RmDoDboxCFWEjYE=
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 4 additions & 4 deletions pkg/updater/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const (

func (c *ClientSet) getGroupVarsFileContent(ctx context.Context, req UpdateReleaseReq) (repoContent *github.RepositoryContent, fileContent string, err error) {
logger := logger.NewFromContextOrDefault(ctx)
logger.Infof("Fetching %q from %s/%s...\n", req.Repo.Path, req.Repo.Owner, req.Repo.Name)
logger.Infof("Fetching %q from %s/%s...", req.Repo.Path, req.Repo.Owner, req.Repo.Name)

repoContent, _, _, err = c.client.GetRepositoryContents(ctx, legacy.GetRepositoryContentsRequest{
Owner: req.Repo.Owner,
Expand All @@ -83,7 +83,7 @@ func (c *ClientSet) getGroupVarsFileContent(ctx context.Context, req UpdateRelea

func (c *ClientSet) getLatestK3sRelease(ctx context.Context, req getLatestK3sReleaseRequest) (latestRelease *github.RepositoryRelease, currentVersion string, err error) {
logger := logger.NewFromContextOrDefault(ctx)
logger.Infof("Fetching the latest k3s release from %s/%s...\n", req.ReleaseRepo.Owner, req.ReleaseRepo.Name)
logger.Infof("Fetching the latest k3s release from %s/%s...", req.ReleaseRepo.Owner, req.ReleaseRepo.Name)

regz := regexp.MustCompile(fmt.Sprintf("%s.*", k3sVersionKey))
extracted := regz.FindStringSubmatch(req.fileContent)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c *ClientSet) getLatestK3sRelease(ctx context.Context, req getLatestK3sRel
// if compared == 1, this means the current
// version is more recent than the other ones.
latestRelease = v
logger.Warnf("A new k3s version is available: %q\n", *latestRelease.Name)
logger.Warnf("A new k3s version is available: %q", *latestRelease.Name)
break
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (c *ClientSet) UpdateK3sRelease(ctx context.Context, req UpdateReleaseReq)

// No update required in this case
if latestRelease.Name == nil {
logger.Infof("Current version %q is the latest version available for k3s, therefore not updating.\n", currentVersion)
logger.Infof("Current version %q is the latest version available for k3s, therefore not updating.", currentVersion)
return nil
}

Expand Down

0 comments on commit ea37f55

Please sign in to comment.