Skip to content

Commit

Permalink
feat: use phuslu log
Browse files Browse the repository at this point in the history
  • Loading branch information
miaolz123 committed Aug 26, 2020
1 parent ad5c76b commit d6bda9e
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 221 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ALL: lint run

.PHONY: gomod
gomod:
rm go.sum && go mod tidy

.PHONY: lint
lint:
golangci-lint run
Expand Down
4 changes: 2 additions & 2 deletions cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"time"

"github.com/gxxgle/go-utils/json"
"github.com/gxxgle/go-utils/log"

"github.com/go-redis/redis/v7"
"github.com/phuslu/log"
)

// RedisConfig is config struct of redis.
Expand Down Expand Up @@ -95,6 +95,6 @@ func (c *RedisCacher) HGet(key, field string, value interface{}) error {

func (c *RedisCacher) Close() {
if err := c.Client.Close(); err != nil {
log.L.WithError(err).Error("go-utils redis close")
log.Error().Err(err).Msg("go-utils redis close")
}
}
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"time"

"github.com/gxxgle/go-utils/env"
"github.com/gxxgle/go-utils/log"

"github.com/doug-martin/goqu/v9"
_ "github.com/doug-martin/goqu/v9/dialect/mysql"
_ "github.com/go-sql-driver/mysql"
"github.com/phuslu/log"
"xorm.io/xorm"
)

Expand Down Expand Up @@ -95,7 +95,7 @@ func Transaction(s *xorm.Session, fn func(*xorm.Session) (error, error)) (dbErr,
dbErr, retErr = fn(s)
if retErr != nil {
if err := s.Rollback(); err != nil {
log.L.WithError(err).Error("go-utils db transaction rollback")
log.Error().Err(err).Msg("go-utils db transaction rollback")
}

return
Expand Down
67 changes: 0 additions & 67 deletions errors/errors.go

This file was deleted.

1 change: 0 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
_ "github.com/gxxgle/go-utils/config"
_ "github.com/gxxgle/go-utils/db"
_ "github.com/gxxgle/go-utils/env"
_ "github.com/gxxgle/go-utils/errors"
_ "github.com/gxxgle/go-utils/ip"
_ "github.com/gxxgle/go-utils/iriser"
_ "github.com/gxxgle/go-utils/json"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ require (
github.com/moul/http2curl v1.0.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/phuslu/log v1.0.39
github.com/robfig/cron/v3 v3.0.1
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shopspring/decimal v1.2.0
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/streadway/amqp v1.0.0
github.com/stretchr/objx v0.3.0 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.10.10 h1:a/y8CglcM7gLGYmlbP/stPE5sR3hbhFRUjCBfd/0B3I=
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down Expand Up @@ -180,6 +178,8 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/phuslu/log v1.0.39 h1:yjqyIR1ahRGlHtlLwvZMlwwAzcrcEaVOCng6eN8wHBc=
github.com/phuslu/log v1.0.39/go.mod h1:BSFbUpGk1VoydawCb63LBAGwv/q6qbaItgrBpehbPsk=
github.com/pkg/errors v0.8.1/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=
Expand All @@ -196,8 +196,6 @@ github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXY
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -278,7 +276,6 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
20 changes: 10 additions & 10 deletions iriser/iriser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"strings"
"time"

"github.com/gxxgle/go-utils/log"

"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/core/router"
"github.com/kataras/iris/v12/middleware/logger"
"github.com/phuslu/log"
)

func Register(r router.Party, h interface{}) {
Expand All @@ -34,7 +33,7 @@ func Register(r router.Party, h interface{}) {
mValue.Call([]reflect.Value{reflect.ValueOf(ctx)})
})

log.L.WithField("path", prefix+"/"+mType.Name).Debug("register handler")
log.Debug().Str("path", prefix+"/"+mType.Name).Msg("go-utils iris register handler")
}
}

Expand All @@ -47,17 +46,18 @@ func NewLogger(ignore func(method, path string) bool) iris.Handler {
if ignore != nil && ignore(ctx.Method(), ctx.Path()) {
return
}
fields := log.F{
"method": ctx.Method(),
"path": ctx.Path(),
"latency_ms": latency.Milliseconds(),
}

lctx := log.NewContext(nil).
Str("method", ctx.Method()).
Str("path", ctx.Path()).
Int64("latency_ms", latency.Milliseconds())
ctx.Values().Visit(func(key string, value interface{}) {
if strings.HasPrefix(key, "log.") {
fields[strings.TrimPrefix(key, "log.")] = value
lctx.Interface(strings.TrimPrefix(key, "log."), value)
}
})
log.L.WithFields(fields).Info("api request")

log.Info().Context(lctx.Value()).Msg("api request")
}
return logger.New(cfg)
}
Binary file removed log/example/bin/example
Binary file not shown.
37 changes: 0 additions & 37 deletions log/example/main.go

This file was deleted.

Loading

0 comments on commit d6bda9e

Please sign in to comment.