From 2d01f8b8548be46ba7428015f187fc50b1ef4d18 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 20 Jul 2021 21:16:53 +0800 Subject: [PATCH] chore: init log package (#606) Signed-off-by: Bo-Yi Wu --- gorush/main_test.go | 10 ---------- logx/log.go | 8 ++------ queue/nsq/README.md | 29 +++++++++++++++++++++++++++++ queue/nsq/nsq_test.go | 10 ---------- queue/simple/simple_test.go | 10 ---------- router/server_test.go | 10 ---------- rpc/server_test.go | 8 -------- status/status_test.go | 12 ------------ 8 files changed, 31 insertions(+), 66 deletions(-) create mode 100644 queue/nsq/README.md diff --git a/gorush/main_test.go b/gorush/main_test.go index 5832fe7..cccd67d 100644 --- a/gorush/main_test.go +++ b/gorush/main_test.go @@ -5,21 +5,11 @@ import ( "testing" "github.com/appleboy/gorush/config" - "github.com/appleboy/gorush/logx" "github.com/appleboy/gorush/status" ) func TestMain(m *testing.M) { cfg, _ := config.LoadConf() - if err := logx.InitLog( - cfg.Log.AccessLevel, - cfg.Log.AccessLog, - cfg.Log.ErrorLevel, - cfg.Log.ErrorLog, - ); err != nil { - log.Fatal(err) - } - if err := status.InitAppStatus(cfg); err != nil { log.Fatal(err) } diff --git a/logx/log.go b/logx/log.go index 1877af5..4b57c4d 100644 --- a/logx/log.go +++ b/logx/log.go @@ -42,19 +42,15 @@ func init() { var ( // LogAccess is log server request log - LogAccess *logrus.Logger + LogAccess = logrus.New() // LogError is log server error log - LogError *logrus.Logger + LogError = logrus.New() ) // InitLog use for initial log module func InitLog(accessLevel, accessLog, errorLevel, errorLog string) error { var err error - // init logger - LogAccess = logrus.New() - LogError = logrus.New() - if !isTerm { LogAccess.SetFormatter(&logrus.JSONFormatter{}) LogError.SetFormatter(&logrus.JSONFormatter{}) diff --git a/queue/nsq/README.md b/queue/nsq/README.md new file mode 100644 index 0000000..204c66f --- /dev/null +++ b/queue/nsq/README.md @@ -0,0 +1,29 @@ +# NSQ + +A realtime distributed messaging platform + +## Setup + +start the NSQ lookupd + +```sh +nsqlookupd +``` + +start the NSQ server + +```sh +nsqd --lookupd-tcp-address=localhost:4160 +``` + +start the NSQ admin dashboard + +```sh +nsqadmin --lookupd-http-address localhost:4161 +``` + +## Testing + +```sh +go test -v ./... +``` diff --git a/queue/nsq/nsq_test.go b/queue/nsq/nsq_test.go index eb0e348..64a537c 100644 --- a/queue/nsq/nsq_test.go +++ b/queue/nsq/nsq_test.go @@ -1,7 +1,6 @@ package nsq import ( - "log" "testing" "time" @@ -21,15 +20,6 @@ func (m mockMessage) Bytes() []byte { } func TestMain(m *testing.M) { - if err := logx.InitLog( - "debug", - "stdout", - "debug", - "stdout", - ); err != nil { - log.Fatalf("Can't load log module, error: %v", err) - } - m.Run() } diff --git a/queue/simple/simple_test.go b/queue/simple/simple_test.go index 32244e8..1365ab3 100644 --- a/queue/simple/simple_test.go +++ b/queue/simple/simple_test.go @@ -1,7 +1,6 @@ package simple import ( - "log" "runtime" "testing" "time" @@ -22,15 +21,6 @@ func (m mockMessage) Bytes() []byte { } func TestMain(m *testing.M) { - if err := logx.InitLog( - "debug", - "stdout", - "debug", - "stdout", - ); err != nil { - log.Fatalf("Can't load log module, error: %v", err) - } - m.Run() } diff --git a/router/server_test.go b/router/server_test.go index 4f604ce..ad223dd 100644 --- a/router/server_test.go +++ b/router/server_test.go @@ -14,7 +14,6 @@ import ( "github.com/appleboy/gorush/config" "github.com/appleboy/gorush/core" "github.com/appleboy/gorush/gorush" - "github.com/appleboy/gorush/logx" "github.com/appleboy/gorush/queue" "github.com/appleboy/gorush/queue/simple" "github.com/appleboy/gorush/status" @@ -33,15 +32,6 @@ var ( func TestMain(m *testing.M) { cfg := initTest() - if err := logx.InitLog( - cfg.Log.AccessLevel, - cfg.Log.AccessLog, - cfg.Log.ErrorLevel, - cfg.Log.ErrorLog, - ); err != nil { - log.Fatal(err) - } - if err := status.InitAppStatus(cfg); err != nil { log.Fatal(err) } diff --git a/rpc/server_test.go b/rpc/server_test.go index 545e308..ac380a0 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/appleboy/gorush/config" - "github.com/appleboy/gorush/logx" "google.golang.org/grpc" "google.golang.org/grpc/connectivity" @@ -21,13 +20,6 @@ func initTest() config.ConfYaml { func TestGracefulShutDownGRPCServer(t *testing.T) { cfg := initTest() - // server configs - logx.InitLog( - cfg.Log.AccessLevel, - cfg.Log.AccessLog, - cfg.Log.ErrorLevel, - cfg.Log.ErrorLog, - ) cfg.GRPC.Enabled = true cfg.GRPC.Port = "9000" cfg.Log.Format = "json" diff --git a/status/status_test.go b/status/status_test.go index 126425f..617001b 100644 --- a/status/status_test.go +++ b/status/status_test.go @@ -1,27 +1,15 @@ package status import ( - "log" "testing" "time" "github.com/appleboy/gorush/config" - "github.com/appleboy/gorush/logx" "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { - cfg, _ := config.LoadConf() - if err := logx.InitLog( - cfg.Log.AccessLevel, - cfg.Log.AccessLog, - cfg.Log.ErrorLevel, - cfg.Log.ErrorLog, - ); err != nil { - log.Fatal(err) - } - m.Run() }