mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
refactor: 日志堆栈描述调整
This commit is contained in:
@@ -142,6 +142,8 @@ const onConnected = () => {
|
||||
return true;
|
||||
});
|
||||
|
||||
state.status = TerminalStatus.Connected;
|
||||
|
||||
// resize
|
||||
sendResize(term.cols, term.rows);
|
||||
// 注册窗口大小监听器
|
||||
@@ -153,8 +155,6 @@ const onConnected = () => {
|
||||
if (props.cmd) {
|
||||
sendCmd(props.cmd + ' \r');
|
||||
}
|
||||
|
||||
state.status = TerminalStatus.Connected;
|
||||
};
|
||||
|
||||
// 自适应终端
|
||||
@@ -220,7 +220,7 @@ enum MsgType {
|
||||
}
|
||||
|
||||
const send = (msg: any) => {
|
||||
socket.send(JSON.stringify(msg));
|
||||
state.status == TerminalStatus.Connected && socket.send(JSON.stringify(msg));
|
||||
};
|
||||
|
||||
const sendResize = (cols: number, rows: number) => {
|
||||
|
||||
@@ -271,7 +271,6 @@ const onShowClusterInfo = async (redis: any) => {
|
||||
const search = async () => {
|
||||
try {
|
||||
pageTableRef.value.loading(true);
|
||||
console.log(state.query);
|
||||
const res = await redisApi.redisList.request(state.query);
|
||||
state.redisTable = res.list;
|
||||
state.total = res.total;
|
||||
|
||||
@@ -30,7 +30,7 @@ func Generate() (string, string) {
|
||||
|
||||
// 验证验证码
|
||||
func Verify(id string, val string) bool {
|
||||
if id == "" || val == "" {
|
||||
if store == nil || id == "" || val == "" {
|
||||
return false
|
||||
}
|
||||
// 同时清理掉这个图片
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"mayfly-go/pkg/utils/runtimex"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,10 +27,10 @@ func GetConfig() *Config {
|
||||
func Init(logConf Config) {
|
||||
config = &logConf
|
||||
var handler slog.Handler
|
||||
if logConf.Type == "text" {
|
||||
handler = NewTextHandler(config)
|
||||
} else {
|
||||
if logConf.IsJsonType() {
|
||||
handler = NewJsonHandler(config)
|
||||
} else {
|
||||
handler = NewTextHandler(config)
|
||||
}
|
||||
slog.SetDefault(slog.New(handler))
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func DebugWithFields(msg string, mapFields map[string]any) {
|
||||
|
||||
// debug记录,并将堆栈信息添加至msg里,默认记录10个堆栈信息
|
||||
func DebugTrace(msg string, err error) {
|
||||
Log(context.Background(), slog.LevelDebug, fmt.Sprintf(msg+"%s\n%s", err.Error(), runtimex.StatckStr(2, 10)))
|
||||
Log(context.Background(), slog.LevelDebug, fmt.Sprintf(msg+" %s\n%s", err.Error(), runtimex.StatckStr(2, 10)))
|
||||
}
|
||||
|
||||
func Info(msg string, args ...any) {
|
||||
@@ -94,7 +94,7 @@ func Errorf(format string, args ...any) {
|
||||
|
||||
// 错误记录,并将堆栈信息添加至msg里,默认记录10个堆栈信息
|
||||
func ErrorTrace(msg string, err error) {
|
||||
Log(context.Background(), slog.LevelError, fmt.Sprintf(msg+"%s\n%s", err.Error(), runtimex.StatckStr(2, 10)))
|
||||
Log(context.Background(), slog.LevelError, fmt.Sprintf(msg+" %s\n%s", err.Error(), runtimex.StatckStr(2, 10)))
|
||||
}
|
||||
|
||||
func ErrorWithFields(msg string, mapFields map[string]any) {
|
||||
@@ -130,7 +130,7 @@ func getCommonAttr(ctx context.Context, level slog.Level) []any {
|
||||
|
||||
source := &Source{
|
||||
Function: f.Function,
|
||||
Fileline: fmt.Sprintf("%s:%d", runtimex.ParseFrameFile(f.File), f.Line),
|
||||
Fileline: fmt.Sprintf("%s:%d", filepath.Base(f.File), f.Line),
|
||||
}
|
||||
commonAttrs = append(commonAttrs, slog.SourceKey, source)
|
||||
}
|
||||
@@ -166,9 +166,5 @@ type Source struct {
|
||||
}
|
||||
|
||||
func (s Source) String() string {
|
||||
// 查找最后一个/的位置, 如mayfly-go/pkg/starter.runWebServer
|
||||
lastIndex := strings.LastIndex(s.Function, "/")
|
||||
// 获取最后一段,即starter.runWebServer
|
||||
funcName := s.Function[lastIndex+1:]
|
||||
return fmt.Sprintf("%s#%s", s.Fileline, funcName)
|
||||
return fmt.Sprintf("%s (%s)", s.Function, s.Fileline)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package runtimex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func StatckStr(skip, nFrames int) string {
|
||||
i := 0
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
fmt.Fprintf(&b, "called from %s (%s:%d)\n\t", frame.Function, ParseFrameFile(frame.File), frame.Line)
|
||||
fmt.Fprintf(&b, "called from %s (%s:%d)\n\t", frame.Function, filepath.Base(frame.File), frame.Line)
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
@@ -33,12 +34,3 @@ func StatckStr(skip, nFrames int) string {
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// 处理栈帧文件名
|
||||
func ParseFrameFile(frameFile string) string {
|
||||
// 尝试将完整路径如/usr/local/.../mayfly-go/server/pkg/starter/web-server.go切割为pkg/starter/web-server.go
|
||||
if ss := strings.Split(frameFile, "mayfly-go/server/"); len(ss) > 1 {
|
||||
return ss[1]
|
||||
}
|
||||
return frameFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user