mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 00:10:25 +08:00 
			
		
		
		
	refactor: 日志堆栈描述调整
This commit is contained in:
		@@ -142,6 +142,8 @@ const onConnected = () => {
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    state.status = TerminalStatus.Connected;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // resize
 | 
					    // resize
 | 
				
			||||||
    sendResize(term.cols, term.rows);
 | 
					    sendResize(term.cols, term.rows);
 | 
				
			||||||
    // 注册窗口大小监听器
 | 
					    // 注册窗口大小监听器
 | 
				
			||||||
@@ -153,8 +155,6 @@ const onConnected = () => {
 | 
				
			|||||||
    if (props.cmd) {
 | 
					    if (props.cmd) {
 | 
				
			||||||
        sendCmd(props.cmd + ' \r');
 | 
					        sendCmd(props.cmd + ' \r');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    state.status = TerminalStatus.Connected;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 自适应终端
 | 
					// 自适应终端
 | 
				
			||||||
@@ -220,7 +220,7 @@ enum MsgType {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const send = (msg: any) => {
 | 
					const send = (msg: any) => {
 | 
				
			||||||
    socket.send(JSON.stringify(msg));
 | 
					    state.status == TerminalStatus.Connected && socket.send(JSON.stringify(msg));
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const sendResize = (cols: number, rows: number) => {
 | 
					const sendResize = (cols: number, rows: number) => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -271,7 +271,6 @@ const onShowClusterInfo = async (redis: any) => {
 | 
				
			|||||||
const search = async () => {
 | 
					const search = async () => {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        pageTableRef.value.loading(true);
 | 
					        pageTableRef.value.loading(true);
 | 
				
			||||||
        console.log(state.query);
 | 
					 | 
				
			||||||
        const res = await redisApi.redisList.request(state.query);
 | 
					        const res = await redisApi.redisList.request(state.query);
 | 
				
			||||||
        state.redisTable = res.list;
 | 
					        state.redisTable = res.list;
 | 
				
			||||||
        state.total = res.total;
 | 
					        state.total = res.total;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ func Generate() (string, string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 验证验证码
 | 
					// 验证验证码
 | 
				
			||||||
func Verify(id string, val string) bool {
 | 
					func Verify(id string, val string) bool {
 | 
				
			||||||
	if id == "" || val == "" {
 | 
						if store == nil || id == "" || val == "" {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 同时清理掉这个图片
 | 
						// 同时清理掉这个图片
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log/slog"
 | 
						"log/slog"
 | 
				
			||||||
	"mayfly-go/pkg/utils/runtimex"
 | 
						"mayfly-go/pkg/utils/runtimex"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
@@ -27,10 +27,10 @@ func GetConfig() *Config {
 | 
				
			|||||||
func Init(logConf Config) {
 | 
					func Init(logConf Config) {
 | 
				
			||||||
	config = &logConf
 | 
						config = &logConf
 | 
				
			||||||
	var handler slog.Handler
 | 
						var handler slog.Handler
 | 
				
			||||||
	if logConf.Type == "text" {
 | 
						if logConf.IsJsonType() {
 | 
				
			||||||
		handler = NewTextHandler(config)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		handler = NewJsonHandler(config)
 | 
							handler = NewJsonHandler(config)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							handler = NewTextHandler(config)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	slog.SetDefault(slog.New(handler))
 | 
						slog.SetDefault(slog.New(handler))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -130,7 +130,7 @@ func getCommonAttr(ctx context.Context, level slog.Level) []any {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		source := &Source{
 | 
							source := &Source{
 | 
				
			||||||
			Function: f.Function,
 | 
								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)
 | 
							commonAttrs = append(commonAttrs, slog.SourceKey, source)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -166,9 +166,5 @@ type Source struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Source) String() string {
 | 
					func (s Source) String() string {
 | 
				
			||||||
	// 查找最后一个/的位置, 如mayfly-go/pkg/starter.runWebServer
 | 
						return fmt.Sprintf("%s (%s)", s.Function, s.Fileline)
 | 
				
			||||||
	lastIndex := strings.LastIndex(s.Function, "/")
 | 
					 | 
				
			||||||
	// 获取最后一段,即starter.runWebServer
 | 
					 | 
				
			||||||
	funcName := s.Function[lastIndex+1:]
 | 
					 | 
				
			||||||
	return fmt.Sprintf("%s#%s", s.Fileline, funcName)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package runtimex
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -21,7 +22,7 @@ func StatckStr(skip, nFrames int) string {
 | 
				
			|||||||
	i := 0
 | 
						i := 0
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		frame, more := frames.Next()
 | 
							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 {
 | 
							if !more {
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -33,12 +34,3 @@ func StatckStr(skip, nFrames int) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return b.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