-
-
Notifications
You must be signed in to change notification settings - Fork 0
Logging
Eshan Roy edited this page Jun 16, 2026
·
2 revisions
M31 Autonomous (M31A) uses Go's structured logging (log/slog) with JSON output, file rotation, and configurable log levels.
Source: internal/log/log.go
func NewLogger(version string) (*slog.Logger, func(), error)The logger is initialized in main.go before any other component:
- Resolve log directory:
~/.m31a/ - Rotate old log files
- Open log file in append mode
- Create handler (JSON or text format)
- Return logger and cleanup function
| Property | Value |
|---|---|
| Path | ~/.m31a/m31a.log |
| Format | JSON (default) or text |
| Append mode | Yes |
| Permission | 0644 |
Daily rotation based on file modification time:
- On startup, check if
m31a.logwas last modified before today - Rename to
m31a.log.YYYY-MM-DD - Remove rotated files older than 7 days
Rotation failure is non-fatal -- the logger continues in append-only mode.
Configured via M31A_LOG_LEVEL environment variable:
| Level | Value |
|---|---|
debug |
Verbose debugging output |
info |
Standard operational messages (default) |
warn |
Warnings and recoverable errors |
error |
Errors only |
Configured via M31A_LOG_FORMAT environment variable:
| Format | Description |
|---|---|
json |
JSON lines (default) -- machine-parseable |
text |
Human-readable key=value format |
The logger is set as the default slog logger:
slog.SetDefault(logger)Components use slog.Info(), slog.Warn(), slog.Error(), and slog.Debug() throughout:
slog.Info("M31A starting", "version", Version, "go_version", runtime.Version())
slog.Warn("keychain initialization failed", "error", kcErr)
slog.Error("failed to load config", "error", err)
slog.Debug("tool executed", "tool", call.Name, "duration_ms", elapsed)# Show recent log entries
/log # default 20 lines
/log 50 # show 50 lines
# Direct file access
cat ~/.m31a/m31a.log
tail -f ~/.m31a/m31a.log