Documentation
¶
Index ¶
- Constants
- func CreateLogDir(logFilePath string) error
- func FromContext(ctx context.Context, fallback *slog.Logger) *slog.Logger
- func IsValidUUIDv7(id string) bool
- func NewClientID() string
- func NewLogger(opts ...LoggerOption) (*slog.Logger, *lumberjack.Logger, error)
- func NewProcessID() string
- func NewRotatingWriter(filename string) *lumberjack.Logger
- func NewRotatingWriterWithConfig(filename string, cfg RotationConfig) *lumberjack.Logger
- func NewSessionID() string
- func ParseLogLevel(level string) (slog.Level, error)
- func ProcessIDFromContext(ctx context.Context) (string, bool)
- func WithClientInfo(logger *slog.Logger, name, version string) *slog.Logger
- func WithComponent(logger *slog.Logger, component string) *slog.Logger
- func WithDaemonSSE(logger *slog.Logger, clientID, clientType, clientVersion string) *slog.Logger
- func WithLogger(ctx context.Context, logger *slog.Logger) context.Context
- func WithMCPProcess(logger *slog.Logger, processID string) *slog.Logger
- func WithProcessID(logger *slog.Logger, processID string) *slog.Logger
- func WithProcessIDContext(ctx context.Context, processID string) context.Context
- func WithSSEClient(logger *slog.Logger) *slog.Logger
- func WithSessionID(logger *slog.Logger, sessionID string) *slog.Logger
- type HandlerType
- type LoggerConfig
- type LoggerOption
- type RotationConfig
Constants ¶
const ( FieldProcessID = "process.id" FieldSessionID = "session.id" FieldRequestID = "request.id" FieldClientID = "client.id" FieldClientType = "client.type" FieldClientVersion = "client.version" FieldComponent = "component" FieldClientName = "client_name" FieldTraceID = "trace_id" // Future: OpenTelemetry )
Standard structured logging field names (avoid magic strings) Uses dot notation for hierarchical namespacing (OpenTelemetry alignment)
const ( ComponentMCPServer = "mcp-server" ComponentSSEClient = "sse-client" ComponentDaemonSSE = "daemon-sse" ComponentGraphManager = "graph-manager" )
Component names
const ( HeaderClientID = "X-Client-ID" HeaderClientType = "X-Client-Type" HeaderClientVersion = "X-Client-Version" )
HTTP headers for client identification
const ( // DefaultMaxSize is the default maximum size in megabytes before rotation DefaultMaxSize = 10 // DefaultMaxBackups is the default number of old log files to retain DefaultMaxBackups = 3 // DefaultMaxAge is the default maximum days to retain old log files DefaultMaxAge = 28 // DefaultCompress enables compression of rotated files DefaultCompress = true )
Variables ¶
This section is empty.
Functions ¶
func CreateLogDir ¶
CreateLogDir creates the directory for a log file path
func FromContext ¶
FromContext retrieves logger from context, returns fallback if not found
func IsValidUUIDv7 ¶
IsValidUUIDv7 validates UUIDv7 format (for testing)
func NewClientID ¶
func NewClientID() string
NewClientID generates a UUIDv7 for client identification
func NewLogger ¶
func NewLogger(opts ...LoggerOption) (*slog.Logger, *lumberjack.Logger, error)
NewLogger creates a logger with optional rotating file output Returns (*slog.Logger, *lumberjack.Logger, error) The lumberjack.Logger is returned for hot-reload scenarios (can be nil)
func NewProcessID ¶
func NewProcessID() string
NewProcessID generates a UUIDv7 for process identification
func NewRotatingWriter ¶
func NewRotatingWriter(filename string) *lumberjack.Logger
NewRotatingWriter creates a lumberjack.Logger with default rotation settings
func NewRotatingWriterWithConfig ¶
func NewRotatingWriterWithConfig(filename string, cfg RotationConfig) *lumberjack.Logger
NewRotatingWriterWithConfig creates a lumberjack.Logger with custom rotation settings
func NewSessionID ¶
func NewSessionID() string
NewSessionID generates a UUIDv7 for session identification
func ParseLogLevel ¶
ParseLogLevel converts string to slog.Level (case-insensitive)
func ProcessIDFromContext ¶
ProcessIDFromContext retrieves process_id from context
func WithClientInfo ¶
WithClientInfo enriches logger with client name and version
func WithComponent ¶
WithComponent enriches logger with component name
func WithDaemonSSE ¶
WithDaemonSSE enriches logger with client.id, client.type, and client.version for daemon SSE
func WithLogger ¶
WithLogger stores logger in context
func WithMCPProcess ¶
WithMCPProcess enriches logger with process_id + component for MCP server
func WithProcessID ¶
WithProcessID enriches logger with process_id
func WithProcessIDContext ¶
WithProcessIDContext stores process_id in context
func WithSSEClient ¶
WithSSEClient enriches logger with component for SSE client
Types ¶
type HandlerType ¶
type HandlerType int
HandlerType specifies the slog handler type
const ( // HandlerJSON creates JSON formatted logs HandlerJSON HandlerType = iota // HandlerText creates human-readable text logs HandlerText )
type LoggerConfig ¶
type LoggerConfig struct {
LogFile string // Path to log file (empty = stdout/stderr)
LogLevel string // "debug", "info", "warn", "error"
Handler HandlerType // JSON or Text
Outputs []io.Writer // Additional writers (for multi-writer)
}
LoggerConfig holds configuration for logger creation
type LoggerOption ¶
type LoggerOption func(*LoggerConfig)
LoggerOption is a functional option for configuring logger creation
func WithAdditionalOutputs ¶
func WithAdditionalOutputs(writers ...io.Writer) LoggerOption
WithAdditionalOutputs adds additional writers (e.g., stderr for MCP)
func WithHandler ¶
func WithHandler(handler HandlerType) LoggerOption
WithHandler sets the handler type
type RotationConfig ¶
type RotationConfig struct {
MaxSize int // megabytes
MaxBackups int // number of backups
MaxAge int // days
Compress bool // compress rotated files
}
RotationConfig holds lumberjack rotation configuration
func DefaultRotationConfig ¶
func DefaultRotationConfig() RotationConfig
DefaultRotationConfig returns default rotation settings