Merge remote-tracking branch 'origin/errcode' into errcode

test-errcode
withchao 2 years ago
commit 8dd2d3054f

@ -65,9 +65,6 @@ func NewZapLogger() (*ZapLogger, error) {
if config.Config.Log.Stderr {
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stderr")
}
zapConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
zapConfig.EncoderConfig.EncodeDuration = zapcore.SecondsDurationEncoder
zapConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
opts, err := zl.cores()
if err != nil {
return nil, err
@ -85,7 +82,12 @@ func (l *ZapLogger) timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
}
func (l *ZapLogger) cores() (zap.Option, error) {
fileEncoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
c := zap.NewProductionEncoderConfig()
c.EncodeTime = zapcore.ISO8601TimeEncoder
c.EncodeDuration = zapcore.SecondsDurationEncoder
//c.EncodeLevel = zapcore.LowercaseColorLevelEncoder
fileEncoder := zapcore.NewJSONEncoder(c)
fileEncoder.AddInt("PID", os.Getpid())
writer, err := l.getWriter()
if err != nil {
return nil, err
@ -143,7 +145,14 @@ func (l *ZapLogger) Error(ctx context.Context, msg string, err error, keysAndVal
}
func (l *ZapLogger) kvAppend(ctx context.Context, keysAndValues []interface{}) []interface{} {
keysAndValues = append([]interface{}{constant.OperationID, tracelog.GetOperationID(ctx), constant.OpUserID, tracelog.GetOpUserID(ctx)}, keysAndValues...)
operationID := tracelog.GetOperationID(ctx)
opUserID := tracelog.GetOpUserID(ctx)
if opUserID != "" {
keysAndValues = append([]interface{}{constant.OpUserID, tracelog.GetOpUserID(ctx)}, keysAndValues...)
}
if operationID != "" {
keysAndValues = append([]interface{}{constant.OperationID, tracelog.GetOperationID(ctx)}, keysAndValues...)
}
return keysAndValues
}

@ -1,6 +1,7 @@
package tracelog
import (
"OpenIM/pkg/common/constant"
"OpenIM/pkg/utils"
"context"
"github.com/sirupsen/logrus"
@ -40,13 +41,18 @@ func GetOperationID(ctx context.Context) string {
return f.OperationID
}
}
return utils.GetFuncName(3)
return ""
}
func GetOpUserID(ctx context.Context) string {
s, _ := ctx.Value("opUserID").(string)
if ctx.Value(constant.OpUserID) != "" {
s, ok := ctx.Value(constant.OpUserID).(string)
if ok {
return s
}
}
return ""
}
func Unwrap(err error) error {
for err != nil {

@ -31,7 +31,7 @@ fi
sleep 1
cd ${msg_gateway_binary_root}
for ((i = 0; i < ${#ws_ports[@]}; i++)); do
echo "==========================start msg_gateway server===========================">>../logs/openIM.log 2>&1 &
echo "==========================start msg_gateway server===========================">>../logs/openIM.log
nohup ./${msg_gateway_name} --port ${rpc_ports[$i]} --ws_port ${ws_ports[$i]} --prometheus_port ${prome_ports[$i]} >>../logs/openIM.log 2>&1 &
done

@ -27,7 +27,7 @@ for ((i = 0; i < ${msg_transfer_service_num}; i++)); do
if [ $prome_port != "" ]; then
cmd="$cmd --prometheus_port $prome_port"
fi
echo "==========================start msg_transfer server===========================">>../logs/openIM.log 2>&1 &
echo "==========================start msg_transfer server===========================">>../logs/openIM.log
$cmd >>../logs/openIM.log 2>&1 &
done

@ -25,7 +25,7 @@ sleep 1
cd ${push_binary_root}
for ((i = 0; i < ${#rpc_ports[@]}; i++)); do
echo "==========================start push server===========================">>../logs/openIM.log 2>&1 &
echo "==========================start push server===========================">>../logs/openIM.log
nohup ./${push_name} --port ${rpc_ports[$i]} --prometheus_port ${prome_ports[$i]} >>../logs/openIM.log 2>&1 &
done

@ -24,7 +24,7 @@ fi
#Waiting port recycling
sleep 1
cd ${sdk_server_binary_root}
echo "==========================start js sdk server===========================">>../logs/openIM.log 2>&1 &
echo "==========================start js sdk server===========================">>../logs/openIM.log
nohup ./${sdk_server_name} -openIM_ws_address ${ws_address} -sdk_ws_port ${sdkws_ports[0]} -openIM_api_address ${api_address} -openIM_log_level ${logLevel} >>../logs/openIM.log 2>&1 &
#Check launched service process

@ -22,7 +22,7 @@ echo "==========================================================">>../logs/openI
for i in ${need_to_start_server_shell[*]}; do
chmod +x $i
echo "=====================exec ${i}======================">>../logs/openIM.log 2>&1 &
echo "=====================exec ${i}======================">>../logs/openIM.log
./$i
if [ $? -ne 0 ]; then
exit -1

@ -18,7 +18,7 @@ sleep 1
cd ${cron_task_binary_root}
#for ((i = 0; i < ${cron_task_service_num}; i++)); do
echo "==========================start cron_task process===========================">>../logs/openIM.log 2>&1 &
echo "==========================start cron_task process===========================">>../logs/openIM.log
nohup ./${cron_task_name} >>../logs/openIM.log 2>&1 &
#done

@ -79,7 +79,7 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
cmd="./${service_filename[$i]} --port ${service_ports[$j]}"
fi
echo $cmd
echo "=====================start ${service_filename[$i]}======================">>../logs/openIM.log 2>&1 &
echo "=====================start ${service_filename[$i]}======================">>../logs/openIM.log
nohup $cmd >>../logs/openIM.log 2>&1 &
sleep 1
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"

Loading…
Cancel
Save