mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
eba9b8ad44
@ -2,7 +2,6 @@ package a2r
|
||||
|
||||
import (
|
||||
"OpenIM/internal/apiresp"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/errs"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -27,13 +26,11 @@ func Call[A, B, C any](
|
||||
}
|
||||
cli, err := client()
|
||||
if err != nil {
|
||||
log.ZError(c, "get rpc client conn failed", err)
|
||||
apiresp.GinError(c, errs.ErrInternalServer.Wrap(err.Error())) // 获取RPC连接失败
|
||||
return
|
||||
}
|
||||
data, err := rpc(cli, c, &req)
|
||||
if err != nil {
|
||||
log.ZError(c, "rpc call failed", err)
|
||||
apiresp.GinError(c, err) // RPC调用失败
|
||||
return
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ func (o *Conversation) client() (conversation.ConversationClient, error) {
|
||||
}
|
||||
|
||||
func (o *Conversation) GetAllConversations(c *gin.Context) {
|
||||
return
|
||||
a2r.Call(conversation.ConversationClient.GetAllConversations, o.client, c)
|
||||
}
|
||||
|
||||
|
@ -47,25 +47,20 @@ func ZError(ctx context.Context, msg string, err error, keysAndValues ...interfa
|
||||
|
||||
type ZapLogger struct {
|
||||
zap *zap.SugaredLogger
|
||||
// store original logger without sampling to avoid multiple samplers
|
||||
SampleDuration time.Duration
|
||||
SampleInitial int
|
||||
SampleInterval int
|
||||
}
|
||||
|
||||
func NewZapLogger() (*ZapLogger, error) {
|
||||
zapConfig := zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
|
||||
Development: true,
|
||||
Encoding: "json",
|
||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||
DisableStacktrace: true,
|
||||
InitialFields: map[string]interface{}{"PID": os.Getegid()},
|
||||
}
|
||||
zl := &ZapLogger{}
|
||||
if config.Config.Log.Stderr {
|
||||
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stderr")
|
||||
}
|
||||
zl := &ZapLogger{}
|
||||
opts, err := zl.cores()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -75,13 +70,10 @@ func NewZapLogger() (*ZapLogger, error) {
|
||||
return nil, err
|
||||
}
|
||||
zl.zap = l.Sugar()
|
||||
zl.zap.WithOptions(zap.AddStacktrace(zap.DPanicLevel))
|
||||
return zl, nil
|
||||
}
|
||||
|
||||
func (l *ZapLogger) timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
||||
enc.AppendString(t.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
func (l *ZapLogger) cores() (zap.Option, error) {
|
||||
c := zap.NewProductionEncoderConfig()
|
||||
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
@ -111,6 +103,14 @@ func (l *ZapLogger) cores() (zap.Option, error) {
|
||||
}), nil
|
||||
}
|
||||
|
||||
func NewErrStackCore(c zapcore.Core) zapcore.Core {
|
||||
return &errStackCore{c}
|
||||
}
|
||||
|
||||
type errStackCore struct {
|
||||
zapcore.Core
|
||||
}
|
||||
|
||||
func (l *ZapLogger) getWriter() (zapcore.WriteSyncer, error) {
|
||||
logf, err := rotatelogs.New(config.Config.Log.StorageLocation+sp+"OpenIM.log.all"+".%Y-%m-%d",
|
||||
rotatelogs.WithRotationCount(config.Config.Log.RemainRotationCount),
|
||||
|
@ -20,7 +20,7 @@ func rpcClientInterceptor(ctx context.Context, method string, req, resp interfac
|
||||
if ctx == nil {
|
||||
return errs.ErrInternalServer.Wrap("call rpc request context is nil")
|
||||
}
|
||||
log.ZInfo(ctx, "rpc client req", "req", "funcName", method, rpcString(req))
|
||||
log.ZInfo(ctx, "rpc client req", "funcName", method, "req", rpcString(req))
|
||||
operationID, ok := ctx.Value(constant.OperationID).(string)
|
||||
if !ok {
|
||||
log.ZWarn(ctx, "ctx missing operationID", errors.New("ctx missing operationID"), "funcName", method)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/mw/specialerror"
|
||||
"OpenIM/pkg/errs"
|
||||
"OpenIM/pkg/proto/wrapperspb"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
@ -65,13 +66,13 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
||||
code = errs.ServerInternalError
|
||||
}
|
||||
grpcStatus := status.New(codes.Code(code), codeErr.Msg())
|
||||
//if unwrap != err {
|
||||
// stack := fmt.Sprintf("%+v", err)
|
||||
// if details, err := grpcStatus.WithDetails(wrapperspb.String(stack)); err == nil {
|
||||
// grpcStatus = details
|
||||
// }
|
||||
//}
|
||||
log.ZWarn(ctx, "rpc resp", unwrap, "funcName", funcName)
|
||||
if unwrap != err {
|
||||
stack := fmt.Sprintf("%+v", err)
|
||||
if details, err := grpcStatus.WithDetails(wrapperspb.String(stack)); err == nil {
|
||||
grpcStatus = details
|
||||
}
|
||||
}
|
||||
log.ZWarn(ctx, "rpc resp", err, "funcName", funcName)
|
||||
return nil, grpcStatus.Err()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user