Skip to content

Commit 1f785d5

Browse files
author
myxy99
committed
log
1 parent a5e269c commit 1f785d5

File tree

15 files changed

+45
-32
lines changed

15 files changed

+45
-32
lines changed

xcode/status.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"github.com/coder2z/g-saber/xjson"
12+
"github.com/coder2z/g-saber/xlog"
1213
"github.com/golang/protobuf/proto"
1314
"github.com/golang/protobuf/ptypes/any"
1415
spb "google.golang.org/genproto/googleapis/rpc/status"
@@ -47,7 +48,7 @@ func (s *spbStatus) IsOk() bool {
4748
// GetMessage ...
4849
func (s *spbStatus) GetMessage(exts ...interface{}) string {
4950
if len(exts)%2 != 0 {
50-
panic("parameter must be odd")
51+
xlog.Panic("parameter must be odd")
5152
}
5253

5354
var buf bytes.Buffer
@@ -107,11 +108,11 @@ func (s *spbStatus) Proto() *spb.Status {
107108

108109
// MustWithDetails ...
109110
func (s *spbStatus) MustWithDetails(details ...interface{}) *spbStatus {
110-
status, err := s.WithDetails(details...)
111+
withDetails, err := s.WithDetails(details...)
111112
if err != nil {
112-
panic(err)
113+
xlog.Panic("MustWithDetails", xlog.FieldErr(err))
113114
}
114-
return status
115+
return withDetails
115116
}
116117

117118
// WithDetails returns a new status with the provided details messages appended to the status.

xcode/xcode.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package xcode
66

77
import (
88
"github.com/coder2z/g-saber/xjson"
9+
"github.com/coder2z/g-saber/xlog"
910
"net/http"
1011
"sync"
1112

@@ -86,15 +87,15 @@ func BusinessCode(code uint32) (spb *spbStatus) {
8687

8788
func SystemCodeAdd(code uint32, message string) *spbStatus {
8889
if code > CodeBreakUp {
89-
panic("customize code must less than 9999")
90+
xlog.Panic("customize code must less than 9999")
9091
}
9192

9293
return add(SystemType, aid*10000+code, message)
9394
}
9495

9596
func BusinessCodeAdd(code uint32, message string) *spbStatus {
9697
if code < CodeBreakUp {
97-
panic("customize code must less than 9999")
98+
xlog.Panic("customize code must less than 9999")
9899
}
99100
return add(BusinessType, code, message)
100101
}

xinvoker/email/invoker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package xemail
77

88
import (
9-
"fmt"
109
"github.com/coder2z/component/xinvoker"
10+
"github.com/coder2z/g-saber/xlog"
1111
"sync"
1212
)
1313

@@ -22,7 +22,8 @@ func Invoker(key string) *Email {
2222
if val, ok := email.instances.Load(key); ok {
2323
return val.(*Email)
2424
}
25-
panic(fmt.Sprintf("no email(%s) invoker found", key))
25+
xlog.Panicf("no email(%s) invoker found", key)
26+
return nil
2627
}
2728

2829
type emailInvoker struct {

xinvoker/gorm/gorm.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package xgorm
22

33
import (
44
"github.com/coder2z/g-saber/xcfg"
5+
"github.com/coder2z/g-saber/xlog"
56
"gorm.io/gorm"
67
"gorm.io/gorm/schema"
78
)
@@ -15,14 +16,14 @@ func (i *dbInvoker) newDatabaseClient(o *options) (db *gorm.DB) {
1516
},
1617
})
1718
if err != nil {
18-
panic(err)
19+
xlog.Panic("NewDatabaseClient OpenDB", xlog.FieldErr(err))
1920
}
2021
if o.Debug {
2122
db = db.Debug()
2223
}
2324
d, err := db.DB()
2425
if err != nil {
25-
panic(err)
26+
xlog.Panic("NewDatabaseClient db.DB()", xlog.FieldErr(err))
2627
}
2728
d.SetMaxOpenConns(o.MaxOpenConnections)
2829
d.SetMaxIdleConns(o.MaxIdleConn)

xinvoker/gorm/invoker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package xgorm
77

88
import (
9-
"fmt"
109
"github.com/coder2z/component/xinvoker"
10+
"github.com/coder2z/g-saber/xlog"
1111
"gorm.io/gorm"
1212
"sync"
1313
)
@@ -23,7 +23,8 @@ func Invoker(key string) *gorm.DB {
2323
if val, ok := db.instances.Load(key); ok {
2424
return val.(*gorm.DB)
2525
}
26-
panic(fmt.Sprintf("no db(%s) invoker found", key))
26+
xlog.Panicf("no db(%s) invoker found", key)
27+
return nil
2728
}
2829

2930
type dbInvoker struct {

xinvoker/mongo/invoker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package xmongo
77

88
import (
9-
"fmt"
109
"github.com/coder2z/component/xinvoker"
10+
"github.com/coder2z/g-saber/xlog"
1111
"sync"
1212
)
1313

@@ -22,7 +22,8 @@ func Invoker(key string) MongoImp {
2222
if val, ok := mongoI.instances.Load(key); ok {
2323
return val.(MongoImp)
2424
}
25-
panic(fmt.Sprintf("no xlog(%s) invoker found", key))
25+
xlog.Panicf("no mongo(%s) invoker found", key)
26+
return nil
2627
}
2728

2829
type mongoInvoker struct {

xinvoker/mongo/mongo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package xmongo
77

88
import (
99
"github.com/coder2z/g-saber/xcfg"
10+
"github.com/coder2z/g-saber/xlog"
1011
"github.com/globalsign/mgo"
1112
)
1213

@@ -78,7 +79,7 @@ func (i *mongoInvoker) new(o *options) MongoImp {
7879
}
7980
resp, err := mgo.DialWithInfo(dialInfo)
8081
if err != nil {
81-
panic(err)
82+
xlog.Panic("new mongo", xlog.FieldErr(err))
8283
}
8384
mgo.SetDebug(o.Debug)
8485
// Optional. Switch the session to a monotonic behavior.

xinvoker/oss/invoker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package xoss
77

88
import (
9-
"fmt"
109
"github.com/coder2z/component/xinvoker"
1110
"github.com/coder2z/component/xinvoker/oss/standard"
11+
"github.com/coder2z/g-saber/xlog"
1212
"sync"
1313
)
1414

@@ -23,7 +23,8 @@ func Invoker(key string) standard.Oss {
2323
if val, ok := ossI.instances.Load(key); ok {
2424
return val.(standard.Oss)
2525
}
26-
panic(fmt.Sprintf("no oss(%s) invoker found", key))
26+
xlog.Panicf("no oss(%s) invoker found", key)
27+
return nil
2728
}
2829

2930
type ossInvoker struct {

xinvoker/oss/oss.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ package xoss
77

88
import (
99
"errors"
10-
"github.com/coder2z/g-saber/xcfg"
1110
"github.com/coder2z/component/xinvoker/oss/alioss"
1211
"github.com/coder2z/component/xinvoker/oss/file"
1312
"github.com/coder2z/component/xinvoker/oss/standard"
13+
"github.com/coder2z/g-saber/xcfg"
14+
"github.com/coder2z/g-saber/xlog"
1415
)
1516

1617
func (i *ossInvoker) loadConfig() map[string]*options {
@@ -35,7 +36,7 @@ func (i *ossInvoker) new(o *options) (client standard.Oss) {
3536
err = errors.New("oss mode not exist")
3637
}
3738
if err != nil {
38-
panic(err)
39+
xlog.Panic("new oss", xlog.FieldErr(err))
3940
}
4041
return
4142
}

xinvoker/redis/invoker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package xredis
77

88
import (
9-
"fmt"
10-
"github.com/go-redis/redis/v8"
119
"github.com/coder2z/component/xinvoker"
10+
"github.com/coder2z/g-saber/xlog"
11+
"github.com/go-redis/redis/v8"
1212
"sync"
1313
)
1414

@@ -23,7 +23,8 @@ func Invoker(key string) *redis.Client {
2323
if val, ok := redisI.instances.Load(key); ok {
2424
return val.(*redis.Client)
2525
}
26-
panic(fmt.Sprintf("no redis(%s) invoker found", key))
26+
xlog.Panicf("no redis(%s) invoker found", key)
27+
return nil
2728
}
2829

2930
type redisInvoker struct {

0 commit comments

Comments
 (0)