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