From 781d90e98b98899cfdd34c7edc4c2159d3c13ee9 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 7 Jan 2019 22:32:50 -0600 Subject: [PATCH] switch to lgr --- Dockerfile.artifacts | 5 + backend/Gopkg.lock | 26 +- backend/Gopkg.toml | 4 - backend/app/cmd/avatar.go | 2 +- backend/app/cmd/backup.go | 2 +- backend/app/cmd/cleanup.go | 3 +- backend/app/cmd/cmd.go | 2 +- backend/app/cmd/import.go | 2 +- backend/app/cmd/import_test.go | 2 +- backend/app/cmd/restore.go | 3 +- backend/app/cmd/server.go | 12 +- backend/app/cmd/server_test.go | 2 +- backend/app/main.go | 15 +- backend/app/main_test.go | 5 +- backend/app/migrator/backup.go | 2 +- backend/app/migrator/disqus.go | 2 +- backend/app/migrator/disqus_test.go | 4 +- backend/app/migrator/migrator.go | 2 +- backend/app/migrator/native.go | 2 +- backend/app/migrator/native_test.go | 2 +- backend/app/migrator/wordpress.go | 2 +- backend/app/notify/notify.go | 3 +- backend/app/notify/notify_test.go | 3 +- backend/app/notify/telegram.go | 2 +- backend/app/notify/telegram_test.go | 1 + backend/app/rest/api/admin.go | 3 +- backend/app/rest/api/migrator.go | 3 +- backend/app/rest/api/migrator_test.go | 3 +- backend/app/rest/api/rest.go | 7 +- backend/app/rest/api/rest_private.go | 5 +- backend/app/rest/api/rest_public.go | 3 +- backend/app/rest/api/rss.go | 5 +- backend/app/rest/api/ssl.go | 2 +- backend/app/rest/httperrors.go | 2 +- backend/app/rest/proxy/image.go | 5 +- backend/app/rest/tree_test.go | 2 +- backend/app/store/admin/admin.go | 3 +- backend/app/store/admin/mongo.go | 3 +- backend/app/store/engine/bolt_accessor.go | 2 +- backend/app/store/engine/bolt_admin.go | 2 +- backend/app/store/engine/mongo.go | 3 +- backend/app/store/service/service.go | 2 +- backend/app/store/service/title.go | 2 +- backend/app/store/user.go | 3 +- .../vendor/github.com/go-pkgz/lgr/.gitignore | 13 + .../vendor/github.com/go-pkgz/lgr/.travis.yml | 19 + backend/vendor/github.com/go-pkgz/lgr/LICENSE | 21 ++ .../vendor/github.com/go-pkgz/lgr/README.md | 48 +++ backend/vendor/github.com/go-pkgz/lgr/go.mod | 3 + backend/vendor/github.com/go-pkgz/lgr/go.sum | 7 + .../github.com/go-pkgz/lgr/interface.go | 41 ++ .../vendor/github.com/go-pkgz/lgr/logger.go | 143 +++++++ .../github.com/go-pkgz/rest/cache/memory.go | 6 +- backend/vendor/github.com/go-pkgz/rest/go.mod | 4 +- backend/vendor/github.com/go-pkgz/rest/go.sum | 8 +- .../github.com/go-pkgz/rest/logger/logger.go | 9 +- .../github.com/go-pkgz/rest/logger/options.go | 9 + .../github.com/go-pkgz/rest/middleware.go | 7 +- .../github.com/hashicorp/logutils/.gitignore | 22 -- .../github.com/hashicorp/logutils/LICENSE | 354 ------------------ .../github.com/hashicorp/logutils/README.md | 36 -- .../github.com/hashicorp/logutils/level.go | 81 ---- 62 files changed, 401 insertions(+), 600 deletions(-) create mode 100644 backend/vendor/github.com/go-pkgz/lgr/.gitignore create mode 100644 backend/vendor/github.com/go-pkgz/lgr/.travis.yml create mode 100644 backend/vendor/github.com/go-pkgz/lgr/LICENSE create mode 100644 backend/vendor/github.com/go-pkgz/lgr/README.md create mode 100644 backend/vendor/github.com/go-pkgz/lgr/go.mod create mode 100644 backend/vendor/github.com/go-pkgz/lgr/go.sum create mode 100644 backend/vendor/github.com/go-pkgz/lgr/interface.go create mode 100644 backend/vendor/github.com/go-pkgz/lgr/logger.go delete mode 100644 backend/vendor/github.com/hashicorp/logutils/.gitignore delete mode 100644 backend/vendor/github.com/hashicorp/logutils/LICENSE delete mode 100644 backend/vendor/github.com/hashicorp/logutils/README.md delete mode 100644 backend/vendor/github.com/hashicorp/logutils/level.go diff --git a/Dockerfile.artifacts b/Dockerfile.artifacts index 829ccea7..faf143e7 100644 --- a/Dockerfile.artifacts +++ b/Dockerfile.artifacts @@ -1,6 +1,11 @@ FROM node:10.11-alpine as build-frontend-deps ARG CI +ARG DRONE +ARG DRONE_TAG +ARG DRONE_COMMIT +ARG DRONE_BRANCH + ENV SKIP_FRONTEND_TEST=true RUN apk add --no-cache --update git diff --git a/backend/Gopkg.lock b/backend/Gopkg.lock index d9b7fde0..0f6ecbb7 100644 --- a/backend/Gopkg.lock +++ b/backend/Gopkg.lock @@ -126,6 +126,14 @@ revision = "6f889bf1c6eb61c926dbb759897e6dc577b10655" version = "v0.3.0" +[[projects]] + digest = "1:01f2a0dea4785957fb0832580a244e693c710130e2785e4a2f73cc7872cdfa82" + name = "github.com/go-pkgz/lgr" + packages = ["."] + pruneopts = "UT" + revision = "5bea4c7108c41005f69ad77c05f516b2228837e2" + version = "v0.1.3" + [[projects]] digest = "1:1212e114344a5cdcc834ea69e19d456eef230f9784659080fee67e02ba2cb574" name = "github.com/go-pkgz/mongo" @@ -146,7 +154,7 @@ version = "v1.0.0" [[projects]] - digest = "1:e133aa7be09588b02198e4ddb98df5033b0319b56533881d0163ee51b903305b" + digest = "1:f90abdc7788e4c799b440eba9ba2c0da647b734d4bd7c0d6a66b8af74d836e67" name = "github.com/go-pkgz/rest" packages = [ ".", @@ -154,8 +162,8 @@ "logger", ] pruneopts = "UT" - revision = "553c0e1b55b215f8f55da4682ac57aff9aec8b6d" - version = "v1.1.5" + revision = "8fbfa5089252d9c40ed780e00e97763c28764e67" + version = "v1.1.6" [[projects]] digest = "1:ffc060c551980d37ee9e428ef528ee2813137249ccebb0bfc412ef83071cac91" @@ -208,14 +216,6 @@ pruneopts = "UT" revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3" -[[projects]] - branch = "master" - digest = "1:ce3f7860fd68bd2dd4c3735e2aed8c9de7c7d05bd6ad7d97a6bedcf4fe7b84fb" - name = "github.com/hashicorp/logutils" - packages = ["."] - pruneopts = "UT" - revision = "0dc08b1671f34c4250ce212759ebd880f743d883" - [[projects]] branch = "master" digest = "1:3217800110ab50cd0e0784307be46b5344c0c103dbd15a16d0994ae4abdc96ab" @@ -403,9 +403,9 @@ "github.com/go-chi/render", "github.com/go-pkgz/auth", "github.com/go-pkgz/auth/avatar", - "github.com/go-pkgz/auth/logger", "github.com/go-pkgz/auth/provider", "github.com/go-pkgz/auth/token", + "github.com/go-pkgz/lgr", "github.com/go-pkgz/mongo", "github.com/go-pkgz/repeater", "github.com/go-pkgz/rest", @@ -414,7 +414,6 @@ "github.com/google/uuid", "github.com/gorilla/feeds", "github.com/hashicorp/go-multierror", - "github.com/hashicorp/logutils", "github.com/jessevdk/go-flags", "github.com/microcosm-cc/bluemonday", "github.com/patrickmn/go-cache", @@ -423,6 +422,7 @@ "github.com/stretchr/testify/assert", "github.com/stretchr/testify/require", "golang.org/x/crypto/acme/autocert", + "golang.org/x/net/html", "gopkg.in/russross/blackfriday.v2", ] solver-name = "gps-cdcl" diff --git a/backend/Gopkg.toml b/backend/Gopkg.toml index 1bdbd4ab..d6e93dbd 100644 --- a/backend/Gopkg.toml +++ b/backend/Gopkg.toml @@ -12,10 +12,6 @@ required = ["github.com/patrickmn/go-cache"] name = "github.com/google/uuid" version = "0.2.0" -[[constraint]] - branch = "master" - name = "github.com/hashicorp/logutils" - [[constraint]] branch = "master" name = "github.com/microcosm-cc/bluemonday" diff --git a/backend/app/cmd/avatar.go b/backend/app/cmd/avatar.go index 82093821..b93d6b32 100644 --- a/backend/app/cmd/avatar.go +++ b/backend/app/cmd/avatar.go @@ -1,11 +1,11 @@ package cmd import ( - "log" "path" "time" bolt "github.com/coreos/bbolt" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/go-pkgz/auth/avatar" diff --git a/backend/app/cmd/backup.go b/backend/app/cmd/backup.go index c0cae341..715e0ded 100644 --- a/backend/app/cmd/backup.go +++ b/backend/app/cmd/backup.go @@ -4,11 +4,11 @@ import ( "context" "fmt" "io" - "log" "net/http" "os" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" ) diff --git a/backend/app/cmd/cleanup.go b/backend/app/cmd/cleanup.go index 0371b1bb..1d03cdcf 100644 --- a/backend/app/cmd/cleanup.go +++ b/backend/app/cmd/cleanup.go @@ -3,13 +3,14 @@ package cmd import ( "encoding/json" "fmt" - "log" "math" "net/http" "strings" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" + "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/cmd/cmd.go b/backend/app/cmd/cmd.go index da177b85..f165bf34 100644 --- a/backend/app/cmd/cmd.go +++ b/backend/app/cmd/cmd.go @@ -5,7 +5,6 @@ package cmd import ( "bytes" "io/ioutil" - "log" "net/http" "os" "path/filepath" @@ -13,6 +12,7 @@ import ( "text/template" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" ) diff --git a/backend/app/cmd/import.go b/backend/app/cmd/import.go index 3b3d85ee..9275a7df 100644 --- a/backend/app/cmd/import.go +++ b/backend/app/cmd/import.go @@ -6,12 +6,12 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "os" "strings" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" ) diff --git a/backend/app/cmd/import_test.go b/backend/app/cmd/import_test.go index 9c50355b..b7846f48 100644 --- a/backend/app/cmd/import_test.go +++ b/backend/app/cmd/import_test.go @@ -3,13 +3,13 @@ package cmd import ( "fmt" "io/ioutil" - "log" "net/http" "net/http/httptest" "strings" "testing" "time" + log "github.com/go-pkgz/lgr" flags "github.com/jessevdk/go-flags" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/backend/app/cmd/restore.go b/backend/app/cmd/restore.go index 708e1975..eeefa2b3 100644 --- a/backend/app/cmd/restore.go +++ b/backend/app/cmd/restore.go @@ -1,8 +1,9 @@ package cmd import ( - "log" "time" + + log "github.com/go-pkgz/lgr" ) // RestoreCommand set of flags and command for restore from backup diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 3af4dff1..4a550f81 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -3,7 +3,6 @@ package cmd import ( "context" "fmt" - "log" "net/http" "net/url" "os" @@ -14,11 +13,12 @@ import ( "time" bolt "github.com/coreos/bbolt" + "github.com/go-pkgz/lgr" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/go-pkgz/auth" "github.com/go-pkgz/auth/avatar" - "github.com/go-pkgz/auth/logger" "github.com/go-pkgz/auth/provider" "github.com/go-pkgz/auth/token" "github.com/go-pkgz/mongo" @@ -170,16 +170,16 @@ func (s *ServerCommand) Execute(args []string) error { stop := make(chan os.Signal, 1) signal.Notify(stop, os.Interrupt, syscall.SIGTERM) <-stop - log.Print("[WARN] interrupt signal") + log.Printf("[WARN] interrupt signal") cancel() }() app, err := s.newServerApp() if err != nil { - log.Fatalf("[ERROR] failed to setup application, %+v", err) + log.Printf("[PANIC] failed to setup application, %+v", err) } if err = app.run(ctx); err != nil { - log.Printf("[WARN] remark terminated with error %+v", err) + log.Printf("[ERROR] remark terminated with error %+v", err) return err } log.Printf("[INFO] remark terminated") @@ -550,7 +550,7 @@ func (s *ServerCommand) makeAuthenticator(ds *service.DataStore, avas avatar.Sto AvatarStore: avas, AvatarResizeLimit: s.Avatar.RszLmt, AvatarRoutePath: "/api/v1/avatar", - Logger: logger.Std, + Logger: lgr.Default(), }) s.addAuthProviders(authenticator) return authenticator diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index dd185494..c0413f0a 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "fmt" "io/ioutil" - "log" "net/http" "os" "strings" @@ -16,6 +15,7 @@ import ( jwt "github.com/dgrijalva/jwt-go" "github.com/globalsign/mgo" "github.com/go-pkgz/auth/token" + log "github.com/go-pkgz/lgr" "github.com/go-pkgz/mongo" flags "github.com/jessevdk/go-flags" diff --git a/backend/app/main.go b/backend/app/main.go index b266442b..171a8830 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -2,13 +2,12 @@ package main import ( "fmt" - "log" "os" "os/signal" "runtime" "syscall" - "github.com/hashicorp/logutils" + log "github.com/go-pkgz/lgr" flags "github.com/jessevdk/go-flags" "github.com/umputun/remark/backend/app/cmd" @@ -62,19 +61,9 @@ func main() { } func setupLog(dbg bool) { - filter := &logutils.LevelFilter{ - Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"}, - MinLevel: logutils.LogLevel("INFO"), - Writer: os.Stdout, - } - - log.SetFlags(log.Ldate | log.Ltime) - if dbg { - log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile) - filter.MinLevel = logutils.LogLevel("DEBUG") + log.Setup(log.Debug, log.Caller) } - log.SetOutput(filter) } // getDump reads runtime stack and returns as a string diff --git a/backend/app/main_test.go b/backend/app/main_test.go index 7981e1d6..d9385171 100644 --- a/backend/app/main_test.go +++ b/backend/app/main_test.go @@ -2,7 +2,6 @@ package main import ( "io/ioutil" - "log" "net/http" "os" "strings" @@ -11,6 +10,8 @@ import ( "testing" "time" + log "github.com/go-pkgz/lgr" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -54,5 +55,5 @@ func TestGetDump(t *testing.T) { assert.True(t, strings.Contains(dump, "goroutine")) assert.True(t, strings.Contains(dump, "[running]")) assert.True(t, strings.Contains(dump, "backend/app/main.go")) - log.Print("\n dump:" + dump) + log.Printf("\n dump: %s", dump) } diff --git a/backend/app/migrator/backup.go b/backend/app/migrator/backup.go index 6d811691..e68a9bc7 100644 --- a/backend/app/migrator/backup.go +++ b/backend/app/migrator/backup.go @@ -5,12 +5,12 @@ import ( "context" "fmt" "io/ioutil" - "log" "os" "sort" "strings" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" ) diff --git a/backend/app/migrator/disqus.go b/backend/app/migrator/disqus.go index ca6b2c5f..bbe0b260 100644 --- a/backend/app/migrator/disqus.go +++ b/backend/app/migrator/disqus.go @@ -3,10 +3,10 @@ package migrator import ( "encoding/xml" "io" - "log" "strings" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/migrator/disqus_test.go b/backend/app/migrator/disqus_test.go index a904159c..334c00e9 100644 --- a/backend/app/migrator/disqus_test.go +++ b/backend/app/migrator/disqus_test.go @@ -7,13 +7,13 @@ import ( "time" bolt "github.com/coreos/bbolt" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/umputun/remark/backend/app/store" "github.com/umputun/remark/backend/app/store/admin" "github.com/umputun/remark/backend/app/store/engine" "github.com/umputun/remark/backend/app/store/service" - - "github.com/stretchr/testify/assert" ) func TestDisqus_Import(t *testing.T) { diff --git a/backend/app/migrator/migrator.go b/backend/app/migrator/migrator.go index 2737c278..a63d56c3 100644 --- a/backend/app/migrator/migrator.go +++ b/backend/app/migrator/migrator.go @@ -5,9 +5,9 @@ package migrator import ( "io" - "log" "os" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/migrator/native.go b/backend/app/migrator/native.go index 79a5b342..b3a03d82 100644 --- a/backend/app/migrator/native.go +++ b/backend/app/migrator/native.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/json" "io" - "log" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/migrator/native_test.go b/backend/app/migrator/native_test.go index 9aeccd56..f6ec722c 100644 --- a/backend/app/migrator/native_test.go +++ b/backend/app/migrator/native_test.go @@ -4,13 +4,13 @@ import ( "bytes" "encoding/json" "fmt" - "log" "os" "strings" "testing" "time" bolt "github.com/coreos/bbolt" + log "github.com/go-pkgz/lgr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/backend/app/migrator/wordpress.go b/backend/app/migrator/wordpress.go index 4596d603..90dce39b 100644 --- a/backend/app/migrator/wordpress.go +++ b/backend/app/migrator/wordpress.go @@ -4,9 +4,9 @@ import ( "encoding/xml" "html" "io" - "log" "time" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/notify/notify.go b/backend/app/notify/notify.go index 4d4f15f4..67b1b7bb 100644 --- a/backend/app/notify/notify.go +++ b/backend/app/notify/notify.go @@ -4,10 +4,11 @@ package notify import ( "context" "fmt" - "log" "sync" "sync/atomic" + log "github.com/go-pkgz/lgr" + "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/notify/notify_test.go b/backend/app/notify/notify_test.go index a57bd98c..b3ca33c5 100644 --- a/backend/app/notify/notify_test.go +++ b/backend/app/notify/notify_test.go @@ -4,14 +4,15 @@ import ( "context" "errors" "fmt" - "log" "math/rand" "sync" "sync/atomic" "testing" "time" + log "github.com/go-pkgz/lgr" "github.com/stretchr/testify/assert" + "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/notify/telegram.go b/backend/app/notify/telegram.go index 72b80c91..a5dd78e3 100644 --- a/backend/app/notify/telegram.go +++ b/backend/app/notify/telegram.go @@ -6,11 +6,11 @@ import ( "encoding/json" "fmt" "html" - "log" "net/http" "strings" "time" + log "github.com/go-pkgz/lgr" "github.com/go-pkgz/repeater" "github.com/pkg/errors" ) diff --git a/backend/app/notify/telegram_test.go b/backend/app/notify/telegram_test.go index 79fe8fb1..c90caf63 100644 --- a/backend/app/notify/telegram_test.go +++ b/backend/app/notify/telegram_test.go @@ -9,6 +9,7 @@ import ( "github.com/go-chi/chi" "github.com/stretchr/testify/assert" + "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/rest/api/admin.go b/backend/app/rest/api/admin.go index 4cd0f420..87667f73 100644 --- a/backend/app/rest/api/admin.go +++ b/backend/app/rest/api/admin.go @@ -2,15 +2,14 @@ package api import ( "errors" - "log" "net/http" "path" "time" "github.com/go-chi/chi" "github.com/go-chi/render" - "github.com/go-pkgz/auth" + log "github.com/go-pkgz/lgr" R "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/cache" diff --git a/backend/app/rest/api/migrator.go b/backend/app/rest/api/migrator.go index 0c2fad0b..b909e531 100644 --- a/backend/app/rest/api/migrator.go +++ b/backend/app/rest/api/migrator.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "os" "sync" @@ -14,7 +13,7 @@ import ( "github.com/go-chi/chi" "github.com/go-chi/render" - + log "github.com/go-pkgz/lgr" R "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/cache" "github.com/pkg/errors" diff --git a/backend/app/rest/api/migrator_test.go b/backend/app/rest/api/migrator_test.go index 17e59794..cc32c556 100644 --- a/backend/app/rest/api/migrator_test.go +++ b/backend/app/rest/api/migrator_test.go @@ -15,11 +15,10 @@ import ( "testing" "time" - "github.com/go-pkgz/auth/token" - bolt "github.com/coreos/bbolt" "github.com/go-chi/chi" "github.com/go-pkgz/auth" + "github.com/go-pkgz/auth/token" "github.com/go-pkgz/rest/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/backend/app/rest/api/rest.go b/backend/app/rest/api/rest.go index 21223f5c..7219a322 100644 --- a/backend/app/rest/api/rest.go +++ b/backend/app/rest/api/rest.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "path" "strings" @@ -19,13 +18,13 @@ import ( "github.com/go-chi/chi/middleware" "github.com/go-chi/cors" "github.com/go-chi/render" - "github.com/pkg/errors" - "github.com/rakyll/statik/fs" - "github.com/go-pkgz/auth" + log "github.com/go-pkgz/lgr" R "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/cache" "github.com/go-pkgz/rest/logger" + "github.com/pkg/errors" + "github.com/rakyll/statik/fs" "github.com/umputun/remark/backend/app/notify" "github.com/umputun/remark/backend/app/rest" diff --git a/backend/app/rest/api/rest_private.go b/backend/app/rest/api/rest_private.go index 21c8c590..303c36ca 100644 --- a/backend/app/rest/api/rest_private.go +++ b/backend/app/rest/api/rest_private.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "log" "net/http" "strings" "time" @@ -13,11 +12,11 @@ import ( jwt "github.com/dgrijalva/jwt-go" "github.com/go-chi/chi" "github.com/go-chi/render" - multierror "github.com/hashicorp/go-multierror" - "github.com/go-pkgz/auth/token" + log "github.com/go-pkgz/lgr" R "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/cache" + multierror "github.com/hashicorp/go-multierror" "github.com/umputun/remark/backend/app/rest" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/rest/api/rest_public.go b/backend/app/rest/api/rest_public.go index cfba32f4..4f49f91d 100644 --- a/backend/app/rest/api/rest_public.go +++ b/backend/app/rest/api/rest_public.go @@ -3,14 +3,13 @@ package api import ( "crypto/sha1" "encoding/base64" - "log" "net/http" "strconv" "strings" "github.com/go-chi/chi" "github.com/go-chi/render" - + log "github.com/go-pkgz/lgr" R "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/cache" diff --git a/backend/app/rest/api/rss.go b/backend/app/rest/api/rss.go index 7e31b7c7..739e44e1 100644 --- a/backend/app/rest/api/rss.go +++ b/backend/app/rest/api/rss.go @@ -2,16 +2,15 @@ package api import ( "fmt" - "log" "net/http" "time" "github.com/go-chi/chi" + log "github.com/go-pkgz/lgr" + "github.com/go-pkgz/rest/cache" "github.com/gorilla/feeds" "github.com/pkg/errors" - "github.com/go-pkgz/rest/cache" - "github.com/umputun/remark/backend/app/rest" "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/rest/api/ssl.go b/backend/app/rest/api/ssl.go index 3310a4a3..ac111007 100644 --- a/backend/app/rest/api/ssl.go +++ b/backend/app/rest/api/ssl.go @@ -2,13 +2,13 @@ package api import ( "crypto/tls" - "log" "net/http" "net/url" "time" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" + log "github.com/go-pkgz/lgr" "golang.org/x/crypto/acme/autocert" R "github.com/go-pkgz/rest" diff --git a/backend/app/rest/httperrors.go b/backend/app/rest/httperrors.go index 77f55df0..e4db2a00 100644 --- a/backend/app/rest/httperrors.go +++ b/backend/app/rest/httperrors.go @@ -2,13 +2,13 @@ package rest import ( "fmt" - "log" "net/http" "net/url" "runtime" "strings" "github.com/go-chi/render" + log "github.com/go-pkgz/lgr" ) // SendErrorJSON makes {error: blah, details: blah} json body and responds with error code diff --git a/backend/app/rest/proxy/image.go b/backend/app/rest/proxy/image.go index c66c7054..17160658 100644 --- a/backend/app/rest/proxy/image.go +++ b/backend/app/rest/proxy/image.go @@ -3,16 +3,15 @@ package proxy import ( "encoding/base64" "io" - "log" "net/http" "strings" "time" "github.com/PuerkitoBio/goquery" "github.com/go-chi/chi" - "github.com/pkg/errors" - + log "github.com/go-pkgz/lgr" "github.com/go-pkgz/repeater" + "github.com/pkg/errors" "github.com/umputun/remark/backend/app/rest" ) diff --git a/backend/app/rest/tree_test.go b/backend/app/rest/tree_test.go index 65892168..114b533e 100644 --- a/backend/app/rest/tree_test.go +++ b/backend/app/rest/tree_test.go @@ -3,10 +3,10 @@ package rest import ( "encoding/json" "io/ioutil" - "log" "testing" "time" + log "github.com/go-pkgz/lgr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/backend/app/store/admin/admin.go b/backend/app/store/admin/admin.go index 1ebebff5..d0b50692 100644 --- a/backend/app/store/admin/admin.go +++ b/backend/app/store/admin/admin.go @@ -3,7 +3,8 @@ package admin import ( "errors" - "log" + + log "github.com/go-pkgz/lgr" ) // Store defines interface returning admins info for given site diff --git a/backend/app/store/admin/mongo.go b/backend/app/store/admin/mongo.go index 0c272c99..1f19bc32 100644 --- a/backend/app/store/admin/mongo.go +++ b/backend/app/store/admin/mongo.go @@ -1,10 +1,9 @@ package admin import ( - "log" - "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" + log "github.com/go-pkgz/lgr" "github.com/go-pkgz/mongo" ) diff --git a/backend/app/store/engine/bolt_accessor.go b/backend/app/store/engine/bolt_accessor.go index f249830d..877febd4 100644 --- a/backend/app/store/engine/bolt_accessor.go +++ b/backend/app/store/engine/bolt_accessor.go @@ -3,11 +3,11 @@ package engine import ( "encoding/json" "fmt" - "log" "strings" "time" bolt "github.com/coreos/bbolt" + log "github.com/go-pkgz/lgr" multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" diff --git a/backend/app/store/engine/bolt_admin.go b/backend/app/store/engine/bolt_admin.go index 5f78b69a..579d34db 100644 --- a/backend/app/store/engine/bolt_admin.go +++ b/backend/app/store/engine/bolt_admin.go @@ -2,10 +2,10 @@ package engine import ( "encoding/json" - "log" "time" bolt "github.com/coreos/bbolt" + log "github.com/go-pkgz/lgr" "github.com/pkg/errors" "github.com/umputun/remark/backend/app/store" diff --git a/backend/app/store/engine/mongo.go b/backend/app/store/engine/mongo.go index 772b22eb..587e7bda 100644 --- a/backend/app/store/engine/mongo.go +++ b/backend/app/store/engine/mongo.go @@ -5,11 +5,10 @@ import ( "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" + "github.com/go-pkgz/mongo" multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" - "github.com/go-pkgz/mongo" - "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/store/service/service.go b/backend/app/store/service/service.go index 61e00fce..1603dc89 100644 --- a/backend/app/store/service/service.go +++ b/backend/app/store/service/service.go @@ -1,11 +1,11 @@ package service import ( - "log" "sort" "sync" "time" + log "github.com/go-pkgz/lgr" "github.com/google/uuid" multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" diff --git a/backend/app/store/service/title.go b/backend/app/store/service/title.go index a2acc31b..30c1e021 100644 --- a/backend/app/store/service/title.go +++ b/backend/app/store/service/title.go @@ -2,9 +2,9 @@ package service import ( "io" - "log" "net/http" + log "github.com/go-pkgz/lgr" "github.com/go-pkgz/rest/cache" "github.com/pkg/errors" "golang.org/x/net/html" diff --git a/backend/app/store/user.go b/backend/app/store/user.go index a0e0cd42..d447d8aa 100644 --- a/backend/app/store/user.go +++ b/backend/app/store/user.go @@ -8,8 +8,9 @@ import ( "hash" "hash/crc64" "io" - "log" "regexp" + + log "github.com/go-pkgz/lgr" ) // User holds user-related info diff --git a/backend/vendor/github.com/go-pkgz/lgr/.gitignore b/backend/vendor/github.com/go-pkgz/lgr/.gitignore new file mode 100644 index 00000000..6e850449 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/.gitignore @@ -0,0 +1,13 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out +vendor diff --git a/backend/vendor/github.com/go-pkgz/lgr/.travis.yml b/backend/vendor/github.com/go-pkgz/lgr/.travis.yml new file mode 100644 index 00000000..3c6ef3e7 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/.travis.yml @@ -0,0 +1,19 @@ +language: go + +go: + - "1.11.x" + +install: true + +before_install: + - export TZ=America/Chicago + - curl -L https://git.io/vp6lP | sh + - go get github.com/mattn/goveralls + - export PATH=$(pwd)/bin:$PATH + +script: + - GO111MODULE=on go get ./... + - GO111MODULE=on go mod vendor + - GO111MODULE=on go test -v -mod=vendor -covermode=count -coverprofile=profile.cov ./... || travis_terminate 1; + - ./bin/gometalinter --deadline=120s --exclude=test --exclude=mock --exclude=vendor --exclude=_example --disable-all --enable=errcheck --enable=vet --enable=vetshadow --enable=megacheck --enable=ineffassign --enable=varcheck --enable=unconvert --enable=deadcode --enable=interfacer --enable=gotype ./... || travis_terminate 1; + - $GOPATH/bin/goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/backend/vendor/github.com/go-pkgz/lgr/LICENSE b/backend/vendor/github.com/go-pkgz/lgr/LICENSE new file mode 100644 index 00000000..ac540250 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Umputun + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/backend/vendor/github.com/go-pkgz/lgr/README.md b/backend/vendor/github.com/go-pkgz/lgr/README.md new file mode 100644 index 00000000..3f6a9a8d --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/README.md @@ -0,0 +1,48 @@ +# lgr - simple logger with some extras [![Build Status](https://travis-ci.org/go-pkgz/lgr.svg?branch=master)](https://travis-ci.org/go-pkgz/lgr) [![Coverage Status](https://coveralls.io/repos/github/go-pkgz/lgr/badge.svg?branch=master)](https://coveralls.io/github/go-pkgz/lgr?branch=master) [![godoc](https://godoc.org/github.com/go-pkgz/lgr?status.svg)](https://godoc.org/github.com/go-pkgz/lgr) + +## install + +`go get github/go-pkgz/lgr` + +## usage + +```go + l := lgr.New(lgr.Debug, lgr.Caller) // allow debug and caller info + l.Logf("INFO some important err message, %v", err) + l.Logf("DEBUG some less important err message, %v", err) +``` + +output looks like this: +``` +2018/01/07 13:02:34.000 INFO {svc/handler.go:101 h.MyFunc1} some important err message, can't open file` +2018/01/07 13:02:34.015 DEBUG {svc/handler.go:155 h.MyFunc2} some less important err message, file is too small` +``` + +_Without `lgr.Caller` it will drop `{caller}` part_ + +## details + +### interfaces and default loggers + +- `lgr` package provides a single interface `lgr.L` with a single method `Logf(format string, args ...interface{})`. Function wrapper `lgr.Func` allows to make `lgr.L` from a function directly. +- Default logger functionality can be used without `lgr.New`, but just `lgr.Printf` +- Two predefined loggers available: `lgr.NoOp` (do-nothing logger) and `lgr.Std` (passing directly to stdlib log) + +### options + +`lgr.New` call accepts functional options: + +- `lgr.Debug` - turn debug mode on. This allows messages with "DEBUG" level (filtered overwise) +- `lgr.Caller` - adds the caller info each message +- `lgr.Out(io.Writer)` - sets the output writer, default `os.Stdout` +- `lgr.Err(io.Writer)` - sets the error writer, default `os.Stderr` + +### levels + +`lgr.Logf` recognizes prefixes like "INFO" or "[INFO]" as levels. The full list of supported levels - "DEBUG", "INFO", "WARN", "ERROR", "PANIC" and "FATAL" + +- `DEBUG` will be filtered unless `lgr.Debug` option defined +- `INFO` and `WARN` don't have any special behavior attached +- `ERROR` sends messages to both out and err writers +- "PANIC" and "FATAL" send messages to both out and err writers. In addition sends dump of callers and runtime info to err only, and call `os.Exit(1)`. + \ No newline at end of file diff --git a/backend/vendor/github.com/go-pkgz/lgr/go.mod b/backend/vendor/github.com/go-pkgz/lgr/go.mod new file mode 100644 index 00000000..6664c915 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/go.mod @@ -0,0 +1,3 @@ +module github.com/go-pkgz/lgr + +require github.com/stretchr/testify v1.3.0 diff --git a/backend/vendor/github.com/go-pkgz/lgr/go.sum b/backend/vendor/github.com/go-pkgz/lgr/go.sum new file mode 100644 index 00000000..4347755a --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/go.sum @@ -0,0 +1,7 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/backend/vendor/github.com/go-pkgz/lgr/interface.go b/backend/vendor/github.com/go-pkgz/lgr/interface.go new file mode 100644 index 00000000..44b97177 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/interface.go @@ -0,0 +1,41 @@ +package lgr + +import stdlog "log" + +var def = New() // default logger doesn't allow DEBUG and doesn't add caller info + +// L defines minimal interface used to log things +type L interface { + Logf(format string, args ...interface{}) +} + +// Func type is an adapter to allow the use of ordinary functions as Logger. +type Func func(format string, args ...interface{}) + +// Logf calls f(id) +func (f Func) Logf(format string, args ...interface{}) { f(format, args...) } + +// NoOp logger +var NoOp = Func(func(format string, args ...interface{}) {}) + +// Std logger sends to std default logger directly +var Std = Func(func(format string, args ...interface{}) { stdlog.Printf(format, args...) }) + +// Printf simplifies replacement of std logger +func Printf(format string, args ...interface{}) { + def.Logf(format, args...) +} + +// Print simplifies replacement of std logger +func Print(line string) { + def.Logf(line) +} + +// Setup default logger with options +func Setup(opts ...Option) { + def = New(opts...) + def.skipCallers = 2 +} + +// Default returns pre-constructed def logger (debug on, callers disabled) +func Default() L { return def } diff --git a/backend/vendor/github.com/go-pkgz/lgr/logger.go b/backend/vendor/github.com/go-pkgz/lgr/logger.go new file mode 100644 index 00000000..ac67af91 --- /dev/null +++ b/backend/vendor/github.com/go-pkgz/lgr/logger.go @@ -0,0 +1,143 @@ +package lgr + +import ( + "fmt" + "io" + "os" + "runtime" + "strings" + "sync" + "time" +) + +var levels = []string{"DEBUG", "INFO", "WARN", "ERROR", "PANIC", "FATAL"} + +// Logger provided simple logger with basic support of levels. Thread safe +type Logger struct { + stdout, stderr io.Writer + dbg bool + lock sync.Mutex + callers bool + now nowFn + fatal panicFn + skipCallers int +} + +type nowFn func() time.Time +type panicFn func() + +// New makes new leveled logger. Accepts dbg flag turing on info about the caller and allowing DEBUG messages/ +// Two writers can be passed optionally - first for out and second for err +func New(options ...Option) *Logger { + res := Logger{ + now: time.Now, + fatal: func() { os.Exit(1) }, + stdout: os.Stdout, + stderr: os.Stderr, + skipCallers: 1, + } + for _, opt := range options { + opt(&res) + } + return &res +} + +// Logf implements L interface to output with printf style. +// Each line prefixed with ts, level and optionally (dbg mode only) by caller info. +// ERROR and FATAL also send the same line to err writer. +// FATAL adds runtime stack and os.exit(1), like panic. +func (l *Logger) Logf(format string, args ...interface{}) { + + lv, msg := l.extractLevel(fmt.Sprintf(format, args...)) + var bld strings.Builder + bld.WriteString(l.now().Format("2006/01/02 15:04:05.000 ")) + bld.WriteString(lv) + + if l.dbg && l.callers { + if pc, file, line, ok := runtime.Caller(l.skipCallers); ok { + fnameElems := strings.Split(file, "/") + funcNameElems := strings.Split(runtime.FuncForPC(pc).Name(), "/") + srcFileInfo := fmt.Sprintf("{%s:%d %s} ", strings.Join(fnameElems[len(fnameElems)-2:], "/"), + line, funcNameElems[len(funcNameElems)-1]) + bld.WriteString(srcFileInfo) + } + } + + if lv == "DEBUG " && !l.dbg { + return + } + bld.WriteString(msg) //nolint + bld.WriteString("\n") //nolint + + l.lock.Lock() + msgb := []byte(bld.String()) + l.stdout.Write(msgb) //nolint + + switch lv { + case "PANIC ", "FATAL ": + l.stderr.Write(msgb) //nolint + l.stderr.Write(getDump()) //nolint + l.fatal() + case "ERROR ": + l.stderr.Write(msgb) //nolint + } + + l.lock.Unlock() +} + +func (l *Logger) extractLevel(line string) (level, msg string) { + spaces := " " + for _, lv := range levels { + if strings.HasPrefix(line, lv) { + if len(lv) == 4 { + spaces = " " + } + return lv + spaces, line[len(lv)+1:] + } + if strings.HasPrefix(line, "["+lv+"]") { + if len(lv) == 4 { + spaces = " " + } + return lv + spaces, line[len(lv)+3:] + } + } + return "", line +} + +// getDump reads runtime stack and returns as a string +func getDump() []byte { + maxSize := 5 * 1024 * 1024 + stacktrace := make([]byte, maxSize) + length := runtime.Stack(stacktrace, true) + if length > maxSize { + length = maxSize + } + return stacktrace[:length] +} + +// Option func type +type Option func(l *Logger) + +// Out sets out writer +func Out(w io.Writer) Option { + return func(l *Logger) { + l.stdout = w + } +} + +// Err sets error writer +func Err(w io.Writer) Option { + return func(l *Logger) { + l.stderr = w + } +} + +// Debug turn on dbg mode +func Debug(l *Logger) { + l.dbg = true +} + +// Caller adds caller info with func, file, and line number +func Caller(l *Logger) { + l.callers = true +} diff --git a/backend/vendor/github.com/go-pkgz/rest/cache/memory.go b/backend/vendor/github.com/go-pkgz/rest/cache/memory.go index a40153b0..c151ef65 100644 --- a/backend/vendor/github.com/go-pkgz/rest/cache/memory.go +++ b/backend/vendor/github.com/go-pkgz/rest/cache/memory.go @@ -1,10 +1,9 @@ package cache import ( - "log" "sync/atomic" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" "github.com/pkg/errors" ) @@ -20,7 +19,6 @@ type memoryCache struct { // NewMemoryCache makes memoryCache implementation func NewMemoryCache(options ...Option) (LoadingCache, error) { - log.Print("[INFO] make memory cache") res := memoryCache{ postFlushFn: func() {}, @@ -44,8 +42,6 @@ func NewMemoryCache(options ...Option) (LoadingCache, error) { return nil, errors.Wrap(err, "failed to make cache") } - log.Printf("[DEBUG] create lru cache, maxKeys=%d, maxValueSize=%d, maxCacheSize=%d", - res.maxKeys, res.maxValueSize, res.maxCacheSize) return &res, nil } diff --git a/backend/vendor/github.com/go-pkgz/rest/go.mod b/backend/vendor/github.com/go-pkgz/rest/go.mod index 19894e8d..9df44c31 100644 --- a/backend/vendor/github.com/go-pkgz/rest/go.mod +++ b/backend/vendor/github.com/go-pkgz/rest/go.mod @@ -2,8 +2,8 @@ module github.com/go-pkgz/rest require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-pkgz/lgr v0.1.3 github.com/hashicorp/golang-lru v0.5.0 github.com/pkg/errors v0.8.0 - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.2 + github.com/stretchr/testify v1.3.0 ) diff --git a/backend/vendor/github.com/go-pkgz/rest/go.sum b/backend/vendor/github.com/go-pkgz/rest/go.sum index aa73c9e6..25d685e7 100644 --- a/backend/vendor/github.com/go-pkgz/rest/go.sum +++ b/backend/vendor/github.com/go-pkgz/rest/go.sum @@ -1,10 +1,14 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-pkgz/lgr v0.1.3 h1:jGPFbzfXWSt3r8qyjXnuKFNM6J10bs3YnD8wPSGdsww= +github.com/go-pkgz/lgr v0.1.3/go.mod h1:hBM1NM/SoYdlrykgdgJWGrZ/TM/XaZIjRbJfx7NkMm8= github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/backend/vendor/github.com/go-pkgz/rest/logger/logger.go b/backend/vendor/github.com/go-pkgz/rest/logger/logger.go index 2bdbc882..65909cd8 100644 --- a/backend/vendor/github.com/go-pkgz/rest/logger/logger.go +++ b/backend/vendor/github.com/go-pkgz/rest/logger/logger.go @@ -5,13 +5,14 @@ import ( "bytes" "fmt" "io/ioutil" - "log" "net" "net/http" "net/url" "regexp" "strings" "time" + + "github.com/go-pkgz/lgr" ) var reMultWhtsp = regexp.MustCompile(`[\s\p{Zs}]{2,}`) @@ -23,6 +24,7 @@ type Middleware struct { flags []Flag ipFn func(ip string) string userFn func(r *http.Request) (string, error) + log lgr.L } // Flag type @@ -38,7 +40,7 @@ const ( // Logger returns default logger middleware func Logger(next http.Handler) http.Handler { - l := New(Flags(All), Prefix("[REST]")) + l := New(Flags(All), Prefix("REST")) return l.Handler(next) } @@ -49,6 +51,7 @@ func New(options ...Option) *Middleware { prefix: "", maxBodySize: 1024, flags: []Flag{All}, + log: lgr.Default(), } for _, opt := range options { opt(&res) @@ -86,7 +89,7 @@ func (l *Middleware) Handler(next http.Handler) http.Handler { remoteIP = l.ipFn(remoteIP) } - log.Printf("%s %s - %s - %s - %d (%d) - %v %s %s", + l.log.Logf("%s %s - %s - %s - %d (%d) - %v %s %s", l.prefix, r.Method, q, remoteIP, ww.status, ww.size, t2.Sub(t1), user, body) }() diff --git a/backend/vendor/github.com/go-pkgz/rest/logger/options.go b/backend/vendor/github.com/go-pkgz/rest/logger/options.go index 99360763..dcdef464 100644 --- a/backend/vendor/github.com/go-pkgz/rest/logger/options.go +++ b/backend/vendor/github.com/go-pkgz/rest/logger/options.go @@ -2,6 +2,8 @@ package logger import ( "net/http" + + "github.com/go-pkgz/lgr" ) // Option func type @@ -43,3 +45,10 @@ func UserFn(userFn func(r *http.Request) (string, error)) Option { l.userFn = userFn } } + +// Log functional option defines loging backend. +func Log(log lgr.L) Option { + return func(l *Middleware) { + l.log = log + } +} diff --git a/backend/vendor/github.com/go-pkgz/rest/middleware.go b/backend/vendor/github.com/go-pkgz/rest/middleware.go index d0dbbe9e..39173386 100644 --- a/backend/vendor/github.com/go-pkgz/rest/middleware.go +++ b/backend/vendor/github.com/go-pkgz/rest/middleware.go @@ -1,11 +1,12 @@ package rest import ( - "log" "net/http" "os" "runtime/debug" "strings" + + log "github.com/go-pkgz/lgr" ) // AppInfo adds custom app-info to the response header @@ -32,9 +33,7 @@ func Ping(next http.Handler) http.Handler { if r.Method == "GET" && strings.HasSuffix(strings.ToLower(r.URL.Path), "/ping") { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - if _, err := w.Write([]byte("pong")); err != nil { - log.Printf("[WARN] can't send pong, %s", err) - } + w.Write([]byte("pong")) //nolint return } next.ServeHTTP(w, r) diff --git a/backend/vendor/github.com/hashicorp/logutils/.gitignore b/backend/vendor/github.com/hashicorp/logutils/.gitignore deleted file mode 100644 index 00268614..00000000 --- a/backend/vendor/github.com/hashicorp/logutils/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe diff --git a/backend/vendor/github.com/hashicorp/logutils/LICENSE b/backend/vendor/github.com/hashicorp/logutils/LICENSE deleted file mode 100644 index c33dcc7c..00000000 --- a/backend/vendor/github.com/hashicorp/logutils/LICENSE +++ /dev/null @@ -1,354 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. “Contributor” - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. “Contributor Version” - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor’s Contribution. - -1.3. “Contribution” - - means Covered Software of a particular Contributor. - -1.4. “Covered Software” - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. “Incompatible With Secondary Licenses” - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of version - 1.1 or earlier of the License, but not also under the terms of a - Secondary License. - -1.6. “Executable Form” - - means any form of the work other than Source Code Form. - -1.7. “Larger Work” - - means a work that combines Covered Software with other material, in a separate - file or files, that is not Covered Software. - -1.8. “License” - - means this document. - -1.9. “Licensable” - - means having the right to grant, to the maximum extent possible, whether at the - time of the initial grant or subsequently, any and all of the rights conveyed by - this License. - -1.10. “Modifications” - - means any of the following: - - a. any file in Source Code Form that results from an addition to, deletion - from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. “Patent Claims” of a Contributor - - means any patent claim(s), including without limitation, method, process, - and apparatus claims, in any patent Licensable by such Contributor that - would be infringed, but for the grant of the License, by the making, - using, selling, offering for sale, having made, import, or transfer of - either its Contributions or its Contributor Version. - -1.12. “Secondary License” - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. “Source Code Form” - - means the form of the work preferred for making modifications. - -1.14. “You” (or “Your”) - - means an individual or a legal entity exercising rights under this - License. For legal entities, “You” includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, “control” means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or as - part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its Contributions - or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution become - effective for each Contribution on the date the Contributor first distributes - such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under this - License. No additional rights or licenses will be implied from the distribution - or licensing of Covered Software under this License. Notwithstanding Section - 2.1(b) above, no patent license is granted by a Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party’s - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of its - Contributions. - - This License does not grant any rights in the trademarks, service marks, or - logos of any Contributor (except as may be necessary to comply with the - notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this License - (see Section 10.2) or under the terms of a Secondary License (if permitted - under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its Contributions - are its original creation(s) or it has sufficient rights to grant the - rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under applicable - copyright doctrines of fair use, fair dealing, or other equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under the - terms of this License. You must inform recipients that the Source Code Form - of the Covered Software is governed by the terms of this License, and how - they can obtain a copy of this License. You may not attempt to alter or - restrict the recipients’ rights in the Source Code Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this License, - or sublicense it under different terms, provided that the license for - the Executable Form does not attempt to limit or alter the recipients’ - rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for the - Covered Software. If the Larger Work is a combination of Covered Software - with a work governed by one or more Secondary Licenses, and the Covered - Software is not Incompatible With Secondary Licenses, this License permits - You to additionally distribute such Covered Software under the terms of - such Secondary License(s), so that the recipient of the Larger Work may, at - their option, further distribute the Covered Software under the terms of - either this License or such Secondary License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices (including - copyright notices, patent notices, disclaimers of warranty, or limitations - of liability) contained within the Source Code Form of the Covered - Software, except that You may alter any license notices to the extent - required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on behalf - of any Contributor. You must make it absolutely clear that any such - warranty, support, indemnity, or liability obligation is offered by You - alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, judicial - order, or regulation then You must: (a) comply with the terms of this License - to the maximum extent possible; and (b) describe the limitations and the code - they affect. Such description must be placed in a text file included with all - distributions of the Covered Software under this License. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing basis, - if such Contributor fails to notify You of the non-compliance by some - reasonable means prior to 60 days after You have come back into compliance. - Moreover, Your grants from a particular Contributor are reinstated on an - ongoing basis if such Contributor notifies You of the non-compliance by - some reasonable means, this is the first time You have received notice of - non-compliance with this License from such Contributor, and You become - compliant prior to 30 days after Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, counter-claims, - and cross-claims) alleging that a Contributor Version directly or - indirectly infringes any patent, then the rights granted to You by any and - all Contributors for the Covered Software under Section 2.1 of this License - shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an “as is” basis, without - warranty of any kind, either expressed, implied, or statutory, including, - without limitation, warranties that the Covered Software is free of defects, - merchantable, fit for a particular purpose or non-infringing. The entire - risk as to the quality and performance of the Covered Software is with You. - Should any Covered Software prove defective in any respect, You (not any - Contributor) assume the cost of any necessary servicing, repair, or - correction. This disclaimer of warranty constitutes an essential part of this - License. No use of any Covered Software is authorized under this License - except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from such - party’s negligence to the extent applicable law prohibits such limitation. - Some jurisdictions do not allow the exclusion or limitation of incidental or - consequential damages, so this exclusion and limitation may not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts of - a jurisdiction where the defendant maintains its principal place of business - and such litigation shall be governed by laws of that jurisdiction, without - reference to its conflict-of-law provisions. Nothing in this Section shall - prevent a party’s ability to bring cross-claims or counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject matter - hereof. If any provision of this License is held to be unenforceable, such - provision shall be reformed only to the extent necessary to make it - enforceable. Any law or regulation which provides that the language of a - contract shall be construed against the drafter shall not be used to construe - this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version of - the License under which You originally received the Covered Software, or - under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a modified - version of this License if you rename the license and remove any - references to the name of the license steward (except to note that such - modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, then -You may include the notice in a location (such as a LICENSE file in a relevant -directory) where a recipient would be likely to look for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - “Incompatible With Secondary Licenses” Notice - - This Source Code Form is “Incompatible - With Secondary Licenses”, as defined by - the Mozilla Public License, v. 2.0. - diff --git a/backend/vendor/github.com/hashicorp/logutils/README.md b/backend/vendor/github.com/hashicorp/logutils/README.md deleted file mode 100644 index 49490eae..00000000 --- a/backend/vendor/github.com/hashicorp/logutils/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# logutils - -logutils is a Go package that augments the standard library "log" package -to make logging a bit more modern, without fragmenting the Go ecosystem -with new logging packages. - -## The simplest thing that could possibly work - -Presumably your application already uses the default `log` package. To switch, you'll want your code to look like the following: - -```go -package main - -import ( - "log" - "os" - - "github.com/hashicorp/logutils" -) - -func main() { - filter := &logutils.LevelFilter{ - Levels: []logutils.LogLevel{"DEBUG", "WARN", "ERROR"}, - MinLevel: logutils.LogLevel("WARN"), - Writer: os.Stderr, - } - log.SetOutput(filter) - - log.Print("[DEBUG] Debugging") // this will not print - log.Print("[WARN] Warning") // this will - log.Print("[ERROR] Erring") // and so will this - log.Print("Message I haven't updated") // and so will this -} -``` - -This logs to standard error exactly like go's standard logger. Any log messages you haven't converted to have a level will continue to print as before. diff --git a/backend/vendor/github.com/hashicorp/logutils/level.go b/backend/vendor/github.com/hashicorp/logutils/level.go deleted file mode 100644 index 6381bf16..00000000 --- a/backend/vendor/github.com/hashicorp/logutils/level.go +++ /dev/null @@ -1,81 +0,0 @@ -// Package logutils augments the standard log package with levels. -package logutils - -import ( - "bytes" - "io" - "sync" -) - -type LogLevel string - -// LevelFilter is an io.Writer that can be used with a logger that -// will filter out log messages that aren't at least a certain level. -// -// Once the filter is in use somewhere, it is not safe to modify -// the structure. -type LevelFilter struct { - // Levels is the list of log levels, in increasing order of - // severity. Example might be: {"DEBUG", "WARN", "ERROR"}. - Levels []LogLevel - - // MinLevel is the minimum level allowed through - MinLevel LogLevel - - // The underlying io.Writer where log messages that pass the filter - // will be set. - Writer io.Writer - - badLevels map[LogLevel]struct{} - once sync.Once -} - -// Check will check a given line if it would be included in the level -// filter. -func (f *LevelFilter) Check(line []byte) bool { - f.once.Do(f.init) - - // Check for a log level - var level LogLevel - x := bytes.IndexByte(line, '[') - if x >= 0 { - y := bytes.IndexByte(line[x:], ']') - if y >= 0 { - level = LogLevel(line[x+1 : x+y]) - } - } - - _, ok := f.badLevels[level] - return !ok -} - -func (f *LevelFilter) Write(p []byte) (n int, err error) { - // Note in general that io.Writer can receive any byte sequence - // to write, but the "log" package always guarantees that we only - // get a single line. We use that as a slight optimization within - // this method, assuming we're dealing with a single, complete line - // of log data. - - if !f.Check(p) { - return len(p), nil - } - - return f.Writer.Write(p) -} - -// SetMinLevel is used to update the minimum log level -func (f *LevelFilter) SetMinLevel(min LogLevel) { - f.MinLevel = min - f.init() -} - -func (f *LevelFilter) init() { - badLevels := make(map[LogLevel]struct{}) - for _, level := range f.Levels { - if level == f.MinLevel { - break - } - badLevels[level] = struct{}{} - } - f.badLevels = badLevels -}