implement panic log for gateway and launcher

add file logger to gateway

ref issue: #1734

Signed-off-by: Cytown <cytown@gmail.com>
This commit is contained in:
Cytown
2026-03-23 15:40:17 +08:00
parent cff9065084
commit df17684dd4
10 changed files with 163 additions and 7 deletions
+15 -5
View File
@@ -33,6 +33,10 @@ import (
const (
appName = "PicoClaw"
logPath = "logs"
panicFile = "launcher_panic.log"
logFile = "launcher.log"
)
var (
@@ -72,6 +76,14 @@ func main() {
// Initialize logger
picoHome := utils.GetPicoclawHome()
f := filepath.Join(picoHome, logPath, panicFile)
panicFunc, err := logger.InitPanic(f)
if err != nil {
panic(fmt.Sprintf("error initializing panic log: %v", err))
}
defer panicFunc()
// By default, detect terminal to decide console log behavior
// If -console-logs flag is explicitly set, it overrides the detection
enableConsole := *console
@@ -79,11 +91,9 @@ func main() {
// Disable console logging by setting level to Fatal (no output)
logger.SetConsoleLevel(logger.FATAL)
logPath := filepath.Join(picoHome, "logs", "web.log")
if err := logger.EnableFileLogging(logPath); err != nil {
// FIXME: https://github.com/sipeed/picoclaw/issues/1734
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
os.Exit(1)
f := filepath.Join(picoHome, logPath, logFile)
if err = logger.EnableFileLogging(f); err != nil {
panic(fmt.Sprintf("error enabling file logging: %v", err))
}
defer logger.DisableFileLogging()
}