Merge 1c953db972 into eb4e187550
This commit is contained in:
commit
e76d8e7322
2 changed files with 45 additions and 1 deletions
|
|
@ -941,7 +941,19 @@ func (h *Handler) startGatewayLocked(initialStatus string, existingPid int) (int
|
|||
// Wait for exit in background and clean up
|
||||
go func() {
|
||||
if err := cmd.Wait(); err != nil {
|
||||
logger.ErrorC("gateway", fmt.Sprintf("Gateway process exited: %v", err))
|
||||
tail := gateway.logs.Tail(50)
|
||||
if len(tail) > 0 {
|
||||
logger.ErrorC(
|
||||
"gateway",
|
||||
fmt.Sprintf(
|
||||
"Gateway process exited: %v\nLast gateway logs:\n%s",
|
||||
err,
|
||||
strings.Join(tail, "\n"),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
logger.ErrorC("gateway", fmt.Sprintf("Gateway process exited: %v", err))
|
||||
}
|
||||
} else {
|
||||
logger.InfoC("gateway", "Gateway process exited normally")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,3 +95,35 @@ func (b *LogBuffer) RunID() int {
|
|||
|
||||
return b.runID
|
||||
}
|
||||
|
||||
// Tail returns up to the last n buffered lines (newest last).
|
||||
// If n <= 0, it returns nil.
|
||||
func (b *LogBuffer) Tail(n int) []string {
|
||||
if n <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
|
||||
if b.total == 0 || len(b.lines) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n > len(b.lines) {
|
||||
n = len(b.lines)
|
||||
}
|
||||
|
||||
result := make([]string, n)
|
||||
|
||||
if b.total <= b.cap {
|
||||
copy(result, b.lines[len(b.lines)-n:])
|
||||
return result
|
||||
}
|
||||
|
||||
start := (b.total - n) % b.cap
|
||||
for i := 0; i < n; i++ {
|
||||
result[i] = b.lines[(start+i)%b.cap]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue