mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 08:01:10 +00:00
fix(logger): write SWu engine logs to the log file
This commit is contained in:
1 parent
466e7fe458
commit
55c46b7690
3 files changed
+39
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/iniwex5/quectel-qmi-go/pkg/qmi"
|
||||
enginelogger "github.com/iniwex5/vowifi-go/engine/logger"
|
||||
"github.com/iniwex5/vowifi-go/runtimehost/carrier"
|
||||
"github.com/iniwex5/vowifi-go/runtimehost/voicehost"
|
||||
"github.com/yibaiba/hideck/internal/api"
|
||||
@@ -32,6 +33,7 @@ import (
|
||||
"github.com/yibaiba/hideck/internal/upstreamproxy"
|
||||
"github.com/yibaiba/hideck/internal/volte"
|
||||
"github.com/yibaiba/hideck/internal/webdavarchive"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/yibaiba/hideck/internal/web"
|
||||
"github.com/yibaiba/hideck/pkg/logger"
|
||||
@@ -59,6 +61,11 @@ func main() {
|
||||
})
|
||||
// 将内置 slog 重定向到已就绪的系统日志框架
|
||||
slog.SetDefault(slog.New(logger.NewSlogHandler(logger.ZapLogger())))
|
||||
// The SWu/IKE engine logs to stderr on its own, so its lines never reached
|
||||
// logs/app.log. Route it through the same console, file and SSE outputs.
|
||||
// pkg/logger adds one caller skip for its own wrappers and the engine
|
||||
// wrappers add theirs, so take one back to report the real caller.
|
||||
enginelogger.Set(logger.ZapLogger().WithOptions(zap.AddCallerSkip(-1)))
|
||||
logger.Info("HiDeck 模组管理器启动中...")
|
||||
|
||||
go func() {
|
||||
|
||||
+12
@@ -68,6 +68,18 @@ func initLogger(level, format string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set routes engine logs through a host logger, for example one that also
|
||||
// writes the host's log file. It must not add its own caller skip. A later
|
||||
// Init call keeps the installed logger.
|
||||
func Set(l *zap.Logger) {
|
||||
if l == nil {
|
||||
return
|
||||
}
|
||||
initOnce.Do(func() {})
|
||||
global.Store(l)
|
||||
globalSugar.Store(l.Sugar())
|
||||
}
|
||||
|
||||
func parseLevel(level string) zapcore.Level {
|
||||
switch level {
|
||||
case "debug":
|
||||
|
||||
@@ -221,3 +221,23 @@ func resetLoggerState() {
|
||||
global.Store(nil)
|
||||
globalSugar.Store(nil)
|
||||
}
|
||||
|
||||
func TestSetRoutesEngineLogsAndSurvivesInit(t *testing.T) {
|
||||
resetLoggerState()
|
||||
defer resetLoggerState()
|
||||
var entries []zapcore.Entry
|
||||
host := zap.New(zapcore.NewCore(zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
|
||||
zapcore.AddSync(io.Discard), zapcore.DebugLevel), zap.AddCaller(),
|
||||
zap.Hooks(func(entry zapcore.Entry) error { entries = append(entries, entry); return nil }))
|
||||
Set(host)
|
||||
if err := Init("error", "json"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Info("routed")
|
||||
if len(entries) != 1 || entries[0].Message != "routed" {
|
||||
t.Fatalf("host entries = %+v, want one routed entry", entries)
|
||||
}
|
||||
if file := filepath.Base(entries[0].Caller.File); file != "logger_test.go" {
|
||||
t.Fatalf("caller = %s, want logger_test.go", entries[0].Caller.File)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user