Skip to content

Commit

Permalink
feat: use sandwich-go/logbus
Browse files Browse the repository at this point in the history
  • Loading branch information
祝黄清 committed Nov 22, 2022
1 parent 442e0c6 commit f624fa6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions driver_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/sandwich-go/logbus/glog"
"github.com/sandwich-go/logbus"
"time"
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func (d *mysqlDriver) renew(ctx context.Context, domain string, quantum uint64)
}
if err != nil {
if err0 := tx.Rollback(); err0 != nil && err0 != sql.ErrTxDone {
glog.Error(w("mysql rollback error"), glog.Err(err0))
logbus.Error(w("mysql rollback error"), logbus.ErrorField(err0))
}
}
}()
Expand Down
14 changes: 9 additions & 5 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/sandwich-go/boost/retry"
"github.com/sandwich-go/boost/xsync"
"github.com/sandwich-go/boost/z"
"github.com/sandwich-go/logbus/glog"
"github.com/sandwich-go/logbus"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -81,6 +81,10 @@ func New(driverName string, opts ...Option) Builder {
if !ok {
panicIfErr(fmt.Errorf("unknown driver %q (forgotten import?)", driverName))
}
return NewWithDriver(driver, opts...)
}

func NewWithDriver(driver Driver, opts ...Option) Builder {
b := &builder{driver: driver, engineGetters: &sync.Map{}, visitor: NewConfig(opts...)}
return b
}
Expand Down Expand Up @@ -256,8 +260,8 @@ func (e *engine) renewWithUnlock() {
e.postRenew(quantum, begin, retry.Do(func(attempt uint) error {
defer func() {
if r := recover(); r != nil {
glog.Error(w("renew panic"), glog.Uint("attempt", attempt), glog.String("domain", e.domain),
glog.Any("recover", r))
logbus.Error(w("renew panic"), logbus.Uint("attempt", attempt), logbus.String("domain", e.domain),
logbus.Any("recover", r))
}
}()
ctx, cancel := context.WithTimeout(context.Background(), e.builder.visitor.GetRenewTimeout())
Expand Down Expand Up @@ -291,7 +295,7 @@ func (e *engine) nextOne() (uint64, error) {
e.renewMutex.Lock()
defer e.renewMutex.Unlock()
if e.nextMax == 0 {
glog.Error(w("next failed"), glog.String("reason", "id run out"), glog.String("domain", e.domain))
logbus.Error(w("next failed"), logbus.String("reason", "id run out"), logbus.String("domain", e.domain))
return 0, ErrIdRunOut
}
e.n = e.nextN
Expand All @@ -311,7 +315,7 @@ func (e *engine) nextOne() (uint64, error) {
e.n++
e.leftReport()
if e.n > e.builder.visitor.GetLimitation() {
glog.Error(w("next failed"), glog.String("reason", "max id"), glog.String("domain", e.domain))
logbus.Error(w("next failed"), logbus.String("reason", "max id"), logbus.String("domain", e.domain))
return 0, ErrReachIdLimitation
}
return e.n, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/prometheus/client_golang v1.14.0
github.com/sandwich-go/boost v0.1.0-alpha.13
github.com/sandwich-go/logbus v0.0.0-20221111114749-eaf446abb132
github.com/sandwich-go/logbus v0.0.0-20221122023007-f5b85631ada7
github.com/satori/go.uuid v1.2.0
github.com/smartystreets/goconvey v1.7.2
go.mongodb.org/mongo-driver v1.11.0
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand All @@ -45,7 +44,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
Expand All @@ -66,7 +64,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fluent/fluent-logger-golang v1.9.0 h1:zUdY44CHX2oIUc7VTNZc+4m+ORuO/mldQDA7czhWXEg=
github.com/fluent/fluent-logger-golang v1.9.0/go.mod h1:2/HCT/jTy78yGyeNGQLGQsjF3zzzAuy6Xlk6FCMV5eU=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -183,7 +180,6 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6f
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -224,8 +220,8 @@ github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/sandwich-go/boost v0.1.0-alpha.13 h1:pO2HSG9a3ACUKCPBAg5uOPnNpGEzHsOZ49HdmbGyksI=
github.com/sandwich-go/boost v0.1.0-alpha.13/go.mod h1:+QRshFyvYEwd9etUjj5DZyqgb+hE09gYm/GzCaaI/q8=
github.com/sandwich-go/logbus v0.0.0-20221111114749-eaf446abb132 h1:/EPUb08ibzA7D1123Grsm29Abg7OC4OK95/Y7ac0m84=
github.com/sandwich-go/logbus v0.0.0-20221111114749-eaf446abb132/go.mod h1:aA2B80lwNZtCPftyi+ZbUhVc58pH6fhNJVh4FkYxRqk=
github.com/sandwich-go/logbus v0.0.0-20221122023007-f5b85631ada7 h1:LwJRHJdMMKSmz3ou/M/vkzKFWg51jS6iAO6ibMdBWvQ=
github.com/sandwich-go/logbus v0.0.0-20221122023007-f5b85631ada7/go.mod h1:aA2B80lwNZtCPftyi+ZbUhVc58pH6fhNJVh4FkYxRqk=
github.com/sandwich-go/zapgen v0.0.0-20220915080429-843fca246b24 h1:KuOgs9R0jfvnloQciDboOubyg8lYO6gbN7odZmrdw+g=
github.com/sandwich-go/zapgen v0.0.0-20220915080429-843fca246b24/go.mod h1:L6T5dpY1oqAduIOpTITKQ6z2LdM2q3lEGoFsac/VISE=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
Expand Down Expand Up @@ -254,7 +250,6 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
Expand Down Expand Up @@ -570,14 +565,12 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
10 changes: 5 additions & 5 deletions reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package siid
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sandwich-go/boost/z"
"github.com/sandwich-go/logbus/glog"
"github.com/sandwich-go/logbus"
"github.com/sandwich-go/logbus/monitor"
)

Expand All @@ -20,12 +20,12 @@ func (e *engine) renewReport(currQuantum uint64, renewBegin z.MonoTimeDuration,
}
if err != nil {
_ = e.renewErrCount.Add(1)
glog.Error(w("renew error"), glog.Err(err), glog.String("domain", e.domain))
logbus.Error(w("renew error"), logbus.ErrorField(err), logbus.String("domain", e.domain))
} else {
_ = e.renewCount.Add(1)
if e.builder.visitor.GetDevelopment() {
glog.Debug(w("renew ok"), glog.Uint64("nextN", e.nextN),
glog.Uint64("quantum", currQuantum), glog.Uint64("nextMax", e.nextMax), glog.String("domain", e.domain))
logbus.Debug(w("renew ok"), logbus.Uint64("nextN", e.nextN),
logbus.Uint64("quantum", currQuantum), logbus.Uint64("nextMax", e.nextMax), logbus.String("domain", e.domain))
}
}
if e.builder.visitor.GetEnableTimeSummary() {
Expand All @@ -46,7 +46,7 @@ func (e *engine) nextReport(n int, nextBegin z.MonoTimeDuration, _ error) {
_ = monitor.Count("siid_next", int64(n), prometheus.Labels{"domain": e.domain})
}
if e.builder.visitor.GetEnableSlow() && cost >= e.builder.visitor.GetSlowQuery() {
glog.Warn(w("next slow query"), glog.Duration("cost", cost), glog.String("domain", e.domain), glog.Int("count", n))
logbus.Warn(w("next slow query"), logbus.Duration("cost", cost), logbus.String("domain", e.domain), logbus.Int("count", n))
}
}

Expand Down

0 comments on commit f624fa6

Please sign in to comment.