浏览代码

add log module

Paul 5 年前
父节点
当前提交
f7760ca72e
共有 5 个文件被更改,包括 92 次插入0 次删除
  1. 14
    0
      log/go.mod
  2. 31
    0
      log/go.sum
  3. 0
    0
      log/hooks/.gitignore
  4. 26
    0
      log/log.go
  5. 21
    0
      log/logger.go

+ 14
- 0
log/go.mod 查看文件

@@ -0,0 +1,14 @@
1
+module git.links123.net/links123.com/pkg/log
2
+
3
+go 1.12
4
+
5
+require (
6
+	github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
7
+	github.com/gin-gonic/gin v1.3.0
8
+	github.com/golang/protobuf v1.3.0 // indirect
9
+	github.com/mattn/go-isatty v0.0.6 // indirect
10
+	github.com/sirupsen/logrus v1.3.0
11
+	github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 // indirect
12
+	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
13
+	gopkg.in/yaml.v2 v2.2.2 // indirect
14
+)

+ 31
- 0
log/go.sum 查看文件

@@ -0,0 +1,31 @@
1
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2
+github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g=
3
+github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
4
+github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
5
+github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
6
+github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
7
+github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
8
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
9
+github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
10
+github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
11
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12
+github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
13
+github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
14
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
16
+github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs=
17
+github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
18
+github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 h1:BasDe+IErOQKrMVXab7UayvSlIpiyGwRvuX3EKYY7UA=
19
+github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA=
20
+golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
21
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
22
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
23
+golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
24
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
25
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
26
+google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
27
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
28
+gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=
29
+gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
30
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
31
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 0
- 0
log/hooks/.gitignore 查看文件


+ 26
- 0
log/log.go 查看文件

@@ -0,0 +1,26 @@
1
+package log
2
+
3
+// Debug is a convenient alias for Root().Debug
4
+func Debug(msg string, ctx ...interface{}) {
5
+	logger.Debug(msg, ctx)
6
+}
7
+
8
+// Info is a convenient alias for Root().Info
9
+func Info(msg string, ctx ...interface{}) {
10
+	logger.Info(msg, ctx)
11
+}
12
+
13
+// Warn is a convenient alias for Root().Warn
14
+func Warn(msg string, ctx ...interface{}) {
15
+	logger.Warn(msg, ctx)
16
+}
17
+
18
+// Error is a convenient alias for Root().Error
19
+func Error(msg string, ctx ...interface{}) {
20
+	logger.Error(msg, ctx)
21
+}
22
+
23
+// Fatal is a convenient alias for Root().Crit
24
+func Fatal(msg string, ctx ...interface{}) {
25
+	logger.Fatal(msg, ctx)
26
+}

+ 21
- 0
log/logger.go 查看文件

@@ -0,0 +1,21 @@
1
+package log
2
+
3
+import (
4
+	"github.com/gin-gonic/gin"
5
+	"github.com/sirupsen/logrus"
6
+)
7
+
8
+var logger *logrus.Logger
9
+
10
+func init() {
11
+	logger = logrus.New()
12
+
13
+	switch gin.Mode() {
14
+	case gin.DebugMode, gin.TestMode:
15
+		logger.SetLevel(logrus.DebugLevel)
16
+	case gin.ReleaseMode:
17
+		logger.SetLevel(logrus.InfoLevel)
18
+	default:
19
+		panic("unsupported running mode")
20
+	}
21
+}