42 lines
957 B
Go
42 lines
957 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
// debugLog is a process-wide append-only log gssh-mcp writes to when
|
|
// SHERLOCK_DEBUG_LOG is set. Identical pattern to gitea-mcp: the
|
|
// agent owns stdin/stdout/stderr, so we can't println during a
|
|
// failing tool call.
|
|
//
|
|
// SHERLOCK_DEBUG_LOG=/tmp/gssh-mcp.log
|
|
//
|
|
// gssh-mcp will tee one line per HTTP request, one line per WS
|
|
// exec start/op/exit, and the OAuth bookkeeping at startup.
|
|
var (
|
|
dbgOnce sync.Once
|
|
dbgLog *log.Logger
|
|
)
|
|
|
|
func dbg(format string, args ...any) {
|
|
dbgOnce.Do(func() {
|
|
path := os.Getenv("SHERLOCK_DEBUG_LOG")
|
|
if path == "" {
|
|
return
|
|
}
|
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "gssh-mcp: SHERLOCK_DEBUG_LOG=%q open: %v\n", path, err)
|
|
return
|
|
}
|
|
dbgLog = log.New(f, "gssh-mcp ", log.LstdFlags|log.Lmicroseconds)
|
|
})
|
|
if dbgLog == nil {
|
|
return
|
|
}
|
|
dbgLog.Printf(format, args...)
|
|
}
|