Skip to content

Commit

Permalink
feat: implment SDK log interface. (#667)
Browse files Browse the repository at this point in the history
* feat: implement panic recovery.

* update recover logic.

* update log print.

* feat: implment SDK log interface.

* update

* remove unused file.

* update Panic log print.
  • Loading branch information
mo3et committed Aug 19, 2024
1 parent 2b6ebb4 commit bbc6472
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 407 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require golang.org/x/net v0.22.0 // indirect
require (
github.com/google/go-cmp v0.6.0
github.com/openimsdk/protocol v0.0.69
github.com/openimsdk/tools v0.0.50-alpha.4
github.com/openimsdk/tools v0.0.50-alpha.7
github.com/patrickmn/go-cache v2.1.0+incompatible
go.uber.org/zap v1.24.0
golang.org/x/image v0.15.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/openimsdk/protocol v0.0.69 h1:dVi8meSg8kmUzSH1XQab4MjihqKkkcCAmt1BYXPJuXo=
github.com/openimsdk/protocol v0.0.69/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.50-alpha.4 h1:OdtWyiVWWHHMaO32nXRBWvPAo4f4lMVQ39zpOn9KKrU=
github.com/openimsdk/tools v0.0.50-alpha.4/go.mod h1:oiSQU5Z6fzjxKFjbqDHImD8EmCIwClU1Rkur1sK12Po=
github.com/openimsdk/tools v0.0.50-alpha.7 h1:zWiE7J4gYk1SHNsSuTqb2o/fpAnBaIomO1yOQcn6N0k=
github.com/openimsdk/tools v0.0.50-alpha.7/go.mod h1:oiSQU5Z6fzjxKFjbqDHImD8EmCIwClU1Rkur1sK12Po=
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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
4 changes: 3 additions & 1 deletion integration_test/internal/pkg/initialization/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package initialization

import (
"fmt"

"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
"github.com/openimsdk/openim-sdk-core/v3/version"
"github.com/openimsdk/tools/log"
Expand All @@ -13,7 +15,7 @@ const (
)

func InitLog(cf sdk_struct.IMConfig) error {
if err := log.InitFromConfig("open-im-sdk-core", "", int(cf.LogLevel), cf.IsLogStandardOutput, false, cf.LogFilePath, rotateCount, rotationTime, version.Version, true); err != nil {
if err := log.InitLoggerFromConfig("open-im-sdk-core", "", cf.SystemType, constant.PlatformID2Name[int(cf.PlatformID)], int(cf.LogLevel), cf.IsLogStandardOutput, false, cf.LogFilePath, rotateCount, rotationTime, version.Version, true); err != nil {
fmt.Println("log init failed ", err.Error())
return err
}
Expand Down
9 changes: 6 additions & 3 deletions internal/interaction/long_conn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ func (c *LongConnMgr) readPump(ctx context.Context) {
defer func() {
if r := recover(); r != nil {
err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack())
log.ZError(ctx, "readPump panic", errs.New(err))

log.ZWarn(ctx, "readPump panic", nil, "panic info", err)
}
}()

Expand Down Expand Up @@ -244,7 +245,8 @@ func (c *LongConnMgr) writePump(ctx context.Context) {
defer func() {
if r := recover(); r != nil {
err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack())
log.ZError(ctx, "writePump panic", errs.New(err))

log.ZWarn(ctx, "writePump panic", nil, "panic info", err)
}
}()
log.ZDebug(ctx, "writePump start", "goroutine ID:", getGoroutineID())
Expand Down Expand Up @@ -299,7 +301,8 @@ func (c *LongConnMgr) heartbeat(ctx context.Context) {
defer func() {
if r := recover(); r != nil {
err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack())
log.ZError(ctx, "heartbeat panic", errs.New(err))

log.ZWarn(ctx, "heartbeat panic", nil, "panic info", err)
}
}()

Expand Down
3 changes: 2 additions & 1 deletion internal/interaction/msg_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func (m *MsgSyncer) DoListener(ctx context.Context) {
defer func() {
if r := recover(); r != nil {
err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack())
log.ZError(ctx, "DoListener panic", errs.New(err))

log.ZWarn(ctx, "DoListener panic", nil, "panic info", err)
}
}()
for {
Expand Down
19 changes: 4 additions & 15 deletions internal/third/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,8 @@ func readLastNLines(filename string, n int) ([]string, error) {
return result, nil
}

func (c *Third) Log(ctx context.Context, logLevel int, file string, line int, msg, err string, keysAndValues []any) {
switch logLevel {
case 6:
// sdklog.SDKDebug(ctx, path, line, msg, keysAndValues)
log.ZDebug(ctx, msg, keysAndValues...)
case 4:
// sdklog.SDKInfo(ctx, path, line, msg, keysAndValues)
log.ZInfo(ctx, msg, keysAndValues...)
case 3:
// sdklog.SDKWarn(ctx, path, line, msg, errs.New(err), keysAndValues)
log.ZWarn(ctx, msg, errs.New(err), keysAndValues...)
case 2:
// sdklog.SDKError(ctx, path, line, msg, errs.New(err), keysAndValues)
log.ZError(ctx, msg, errs.New(err), keysAndValues...)
}
func (c *Third) SDKLogs(ctx context.Context, logLevel int, file string, line int, msg, err string, keysAndValues []any) {
errString := errs.New(err)

log.SDKLog(ctx, logLevel, file, line, msg, errString, keysAndValues)
}
Loading

0 comments on commit bbc6472

Please sign in to comment.