From c3cd41a24f3937b5b56dca3b5466307018d42d37 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 30 Nov 2020 17:48:09 -0700 Subject: [PATCH] wrap log --- internal/api/api.go | 14 +++++++------- internal/log/log.go | 10 ++++++++++ internal/webhooks/bitbucket/bitbucket.go | 4 ++-- internal/webhooks/gitea/gitea.go | 2 +- internal/webhooks/github/github.go | 2 +- main.go | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 internal/log/log.go diff --git a/internal/api/api.go b/internal/api/api.go index e3990c7..0c3a95a 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "os" "os/exec" @@ -13,6 +12,7 @@ import ( "strings" "time" + "git.rootprojects.org/root/gitdeploy/internal/log" "git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/webhooks" @@ -79,7 +79,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) { // r.Body is always .Close()ed by Go's http server r.Body = http.MaxBytesReader(w, r.Body, options.DefaultMaxBodySize) // TODO admin auth middleware - log.Println("TODO: handle authentication") + log.Printf("TODO: handle authentication") next.ServeHTTP(w, r) }) }) @@ -153,7 +153,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) { decoder := json.NewDecoder(r.Body) msg := &KillMsg{} if err := decoder.Decode(msg); nil != err { - log.Println("kill job invalid json:", err) + log.Printf("kill job invalid json:\n%v", err) http.Error(w, "invalid json body", http.StatusBadRequest) return } @@ -178,12 +178,12 @@ func Route(r chi.Router, runOpts *options.ServerConfig) { decoder := json.NewDecoder(r.Body) msg := &webhooks.Ref{} if err := decoder.Decode(msg); nil != err { - log.Println("promotion job invalid json:", err) + log.Printf("promotion job invalid json:\n%v", err) http.Error(w, "invalid json body", http.StatusBadRequest) return } if "" == msg.HTTPSURL || "" == msg.RefName { - log.Println("promotion job incomplete json", msg) + log.Printf("promotion job incomplete json %s", msg) http.Error(w, "incomplete json body", http.StatusBadRequest) return } @@ -196,7 +196,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) { } } if n < 0 { - log.Println("promotion job invalid: cannot promote:", n) + log.Printf("promotion job invalid: cannot promote: %d", n) http.Error(w, "invalid promotion", http.StatusBadRequest) return } @@ -319,7 +319,7 @@ func remove(jobID string, nokill bool) { if nil != job.Cmd.Process { // but definitely was started err := job.Cmd.Process.Kill() - log.Println("error killing job:", err) + log.Printf("error killing job:\n%v", err) } } } diff --git a/internal/log/log.go b/internal/log/log.go new file mode 100644 index 0000000..bd13a99 --- /dev/null +++ b/internal/log/log.go @@ -0,0 +1,10 @@ +package log + +import ( + "log" +) + +// Printf wraps log.Printf +func Printf(msg string, els ...interface{}) { + log.Printf(msg, els...) +} diff --git a/internal/webhooks/bitbucket/bitbucket.go b/internal/webhooks/bitbucket/bitbucket.go index be8c7b2..7fc5197 100644 --- a/internal/webhooks/bitbucket/bitbucket.go +++ b/internal/webhooks/bitbucket/bitbucket.go @@ -5,11 +5,11 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "os" "strings" + "git.rootprojects.org/root/gitdeploy/internal/log" "git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/webhooks" @@ -114,7 +114,7 @@ func InitWebhook(providername string, secretList *string, envname string) func() branch = refName ref = fmt.Sprintf("refs/heads/%s", refName) default: - log.Println("unexpected bitbucket RefType", refType) + log.Printf("unexpected bitbucket RefType %s\n", refType) ref = fmt.Sprintf("refs/UNKNOWN/%s", refName) } diff --git a/internal/webhooks/gitea/gitea.go b/internal/webhooks/gitea/gitea.go index f0f146a..2d64732 100644 --- a/internal/webhooks/gitea/gitea.go +++ b/internal/webhooks/gitea/gitea.go @@ -7,11 +7,11 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "os" "strings" + "git.rootprojects.org/root/gitdeploy/internal/log" "git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/webhooks" diff --git a/internal/webhooks/github/github.go b/internal/webhooks/github/github.go index 3145dd4..ff1bb2e 100644 --- a/internal/webhooks/github/github.go +++ b/internal/webhooks/github/github.go @@ -3,11 +3,11 @@ package github import ( "fmt" "io/ioutil" - "log" "net/http" "os" "strings" + "git.rootprojects.org/root/gitdeploy/internal/log" "git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/webhooks" diff --git a/main.go b/main.go index b60efde..b2997af 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "flag" "fmt" - "log" "net/http" "os" "path/filepath" @@ -15,6 +14,7 @@ import ( "git.rootprojects.org/root/gitdeploy/assets/examples" "git.rootprojects.org/root/gitdeploy/assets/public" "git.rootprojects.org/root/gitdeploy/internal/api" + "git.rootprojects.org/root/gitdeploy/internal/log" "git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/webhooks" "git.rootprojects.org/root/vfscopy"