feat: add structured logging with log/slog and panic recovery
Replace log.Printf/Println with slog.Info/Error/Warn across the codebase. Initialize slog with JSON handler in main.go. Add panic recovery defer in SSH session handler. Add structured game event logging (room created, player joined, game started, game over, player inactive removed). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -143,6 +144,7 @@ func (s *GameSession) combatLoop() {
|
||||
s.mu.Unlock()
|
||||
|
||||
if gameOver {
|
||||
slog.Info("game over", "floor", s.state.FloorNum, "victory", s.state.Victory)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -155,6 +157,7 @@ func (s *GameSession) combatLoop() {
|
||||
if p.Fingerprint != "" && !p.IsOut() {
|
||||
if last, ok := s.lastActivity[p.Fingerprint]; ok {
|
||||
if now.Sub(last) > 60*time.Second {
|
||||
slog.Warn("player inactive removed", "fingerprint", p.Fingerprint, "name", p.Name)
|
||||
s.addLog(fmt.Sprintf("%s removed (disconnected)", p.Name))
|
||||
changed = true
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user