feat: better debugger (#13)
- create centralized structured logger with rotation (https://github.com/versenilvis/IRIS/commit/96ad7c95ef0f7a9957b1bbf70bb6c8da3ce28b2e) - update core lookup and utils to use new logger (https://github.com/versenilvis/IRIS/commit/8b74b5a9cdc1828cff8c6d0bdaaccbe31da7a00a) - add log startup metadata and propagate reload flags (https://github.com/versenilvis/IRIS/commit/31208aa91a58e9e09abbf5497c314f5c961a58e2) - add log key interceptions and pty events (https://github.com/versenilvis/IRIS/commit/91ccb92835dd16ee70bf630fe0f267aad93c9db0) - add test for logger 221a40c893b75e6215787163cd751a4c1cb6c1d8 - secure reload arguments file path to prevent symlink attacks (https://github.com/versenilvis/IRIS/pull/13/commits/c3eabfda451230e52cb71f0c2a556687f839bd3f) - close log file on reinitialization to prevent descriptor leak (https://github.com/versenilvis/IRIS/pull/13/commits/a57d2c9be107a8c6200cf7046cc85b2f58667dce)
This commit is contained in:
+13
-18
@@ -8,13 +8,15 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
_ "github.com/versenilvis/iris/commands"
|
||||
"github.com/versenilvis/iris/config"
|
||||
"github.com/versenilvis/iris/logger"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
@@ -36,6 +38,10 @@ It works exactly like coding editor suggestion menu drop down.`,
|
||||
}()
|
||||
if pidStr := os.Getenv("IRIS_PID"); pidStr != "" {
|
||||
if pid, err := strconv.Atoi(pidStr); err == nil && pid > 0 {
|
||||
if logDir, err := config.CachePath(); err == nil {
|
||||
argsFile := filepath.Join(logDir, "reload-args")
|
||||
_ = os.WriteFile(argsFile, []byte(strings.Join(os.Args[1:], "\n")), 0600)
|
||||
}
|
||||
_ = syscall.Kill(pid, syscall.SIGUSR1)
|
||||
fmt.Println("\r\033[K\033[36m[IRIS] Sent reload signal to parent session.\033[0m")
|
||||
return
|
||||
@@ -46,7 +52,6 @@ It works exactly like coding editor suggestion menu drop down.`,
|
||||
}
|
||||
shellFlag string
|
||||
debugMode bool
|
||||
debugLogger *os.File
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -57,26 +62,16 @@ func init() {
|
||||
if shellFlag != "" {
|
||||
config.Get().Core.Shell = shellFlag
|
||||
}
|
||||
config.Get().Core.Debug = true
|
||||
if config.Get().Core.Debug {
|
||||
logDir, err := config.CachePath()
|
||||
if err == nil {
|
||||
_ = os.MkdirAll(logDir, 0755)
|
||||
f, _ := os.OpenFile(filepath.Join(logDir, "iris.log"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
debugLogger = f
|
||||
core.DebugWriter = f
|
||||
_, _ = fmt.Fprintf(debugLogger, "--- IRIS DEBUG LOG ---\n")
|
||||
}
|
||||
logDir, err := config.CachePath()
|
||||
if err == nil {
|
||||
logger.Init(filepath.Join(logDir, "iris.log"), debugMode || config.Get().Core.Debug)
|
||||
logger.Infof("IRIS session started: os=%s, arch=%s, go=%s, pid=%d", runtime.GOOS, runtime.GOARCH, runtime.Version(), os.Getpid())
|
||||
cfg := config.Get()
|
||||
logger.Debugf("IRIS loaded config: shell=%q, mode=%q, ghost-text=%v, max-suggestions=%d", cfg.Core.Shell, cfg.Core.Mode, cfg.UI.GhostText, cfg.UI.MaxSuggestions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func debugLog(format string, a ...any) {
|
||||
if debugLogger != nil {
|
||||
_, _ = fmt.Fprintf(debugLogger, format+"\n", a...)
|
||||
}
|
||||
}
|
||||
|
||||
// runWatchdog spawns the watchdog parent process
|
||||
func runWatchdog() {
|
||||
exe, err := os.Executable()
|
||||
|
||||
Reference in New Issue
Block a user