whao 5 年 前
コミット
6166293bfd
共有3 個のファイルを変更した56 個の追加3 個の削除を含む
  1. 26
    0
      log/hooks/client_test.go
  2. 2
    3
      log/logger.go
  3. 28
    0
      log/logger_test.go

+ 26
- 0
log/hooks/client_test.go ファイルの表示

@@ -0,0 +1,26 @@
1
+package hooks
2
+
3
+import (
4
+	"fmt"
5
+	"testing"
6
+	"time"
7
+
8
+	"github.com/sirupsen/logrus"
9
+)
10
+
11
+func FTestClient_Notify(t *testing.T) {
12
+	NewClient("127.0.0.1", 8085)
13
+	resp, err := defaultClient.Notify(&NotifyRequest{
14
+		Project:     "xxx",
15
+		Maintainers: []string{"x", "Y"},
16
+		Message:     "message",
17
+		Time:        time.Now().String(),
18
+	})
19
+	if err != nil {
20
+		fmt.Println("err===>", err)
21
+	}
22
+
23
+	logrus.Debug()
24
+
25
+	fmt.Println("resp===>", resp)
26
+}

+ 2
- 3
log/logger.go ファイルの表示

@@ -6,7 +6,7 @@ import (
6 6
 	"github.com/sirupsen/logrus"
7 7
 )
8 8
 
9
-var logger *logrus.Logger
9
+var logger = logrus.New()
10 10
 
11 11
 func NewDefaultLogger(project *hooks.Project) error {
12 12
 	return NewLogger(project, hooks.DefaultMaintainers(), hooks.DefaultNotificationService())
@@ -18,8 +18,7 @@ func NewLogger(project *hooks.Project, maintainers []*hooks.Maintainer, ns *hook
18 18
 		return err
19 19
 	}
20 20
 
21
-	logrus.AddHook(notificationHook)
22
-	logger = logrus.New()
21
+	logger.AddHook(notificationHook)
23 22
 
24 23
 	switch gin.Mode() {
25 24
 	case gin.DebugMode, gin.TestMode:

+ 28
- 0
log/logger_test.go ファイルの表示

@@ -0,0 +1,28 @@
1
+package log
2
+
3
+import (
4
+	"testing"
5
+
6
+	"git.links123.net/links123.com/pkg/log/hooks"
7
+)
8
+
9
+func TestNewDefaultLogger(t *testing.T) {
10
+	err := NewDefaultLogger(&hooks.Project{Name: "n1", Domain: "d1"})
11
+	if err != nil {
12
+		panic(err)
13
+	}
14
+
15
+	Debug("debug message")
16
+
17
+	//hook, err := hooks.NewNotificationHook(&hooks.Project{Name: "xxx", Domain: "domain"}, hooks.DefaultMaintainers(), hooks.DefaultNotificationService())
18
+	//if err != nil {
19
+	//	panic(err)
20
+	//}
21
+	//logger := logrus.New()
22
+	//logger.AddHook(hook)
23
+	//
24
+	//logger.Debug("debug info")
25
+	//logger.Info("info info")
26
+	//logger.Fatal("fatal info")
27
+	//logger.Error("error info")
28
+}