Documentation
¶
Index ¶
- func Debug(msg string, fields ...Field)
- func Error(msg string, fields ...Field)
- func Fatal(msg string, fields ...Field)
- func FormatError(err error) string
- func Info(msg string, fields ...Field)
- func InitLogBuffer(maxSize int)
- func InitMCPLogger(maxSize int)
- func InitializeLogging(level string, debugMode bool)
- func IsErrorCode(err error, code ErrorCode) bool
- func LogMCPIncoming(rawMessage string, parsedMessage interface{})
- func LogMCPOutgoing(rawMessage string, parsedMessage interface{})
- func RecoveryHandler()
- func SetGlobalLevel(level LogLevel)
- func SetGlobalOutput(w io.Writer)
- func Shutdown()
- func Warn(msg string, fields ...Field)
- type ErrorCode
- type Field
- type LogBuffer
- type LogEntry
- type LogLevel
- type Logger
- type MCPError
- type MCPLogEntry
- type MCPLogger
- func (ml *MCPLogger) Clear()
- func (ml *MCPLogger) GetEntries() []MCPLogEntry
- func (ml *MCPLogger) GetEntriesAsStrings() []string
- func (ml *MCPLogger) GetStats() map[string]int
- func (ml *MCPLogger) LogIncoming(rawMessage string, parsedMessage interface{})
- func (ml *MCPLogger) LogOutgoing(rawMessage string, parsedMessage interface{})
- func (ml *MCPLogger) Size() int
- type MCPMessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatError ¶
FormatError formats an error for display to users
func InitLogBuffer ¶
func InitLogBuffer(maxSize int)
InitLogBuffer initializes the global log buffer
func InitMCPLogger ¶
func InitMCPLogger(maxSize int)
InitMCPLogger initializes the global MCP logger
func InitializeLogging ¶
InitializeLogging sets up logging based on environment
func IsErrorCode ¶
IsErrorCode checks if an error has a specific error code
func LogMCPIncoming ¶
func LogMCPIncoming(rawMessage string, parsedMessage interface{})
LogMCPIncoming logs an incoming MCP message
func LogMCPOutgoing ¶
func LogMCPOutgoing(rawMessage string, parsedMessage interface{})
LogMCPOutgoing logs an outgoing MCP message
func RecoveryHandler ¶
func RecoveryHandler()
RecoveryHandler handles panics and converts them to errors
func SetGlobalLevel ¶
func SetGlobalLevel(level LogLevel)
SetGlobalLevel sets the global logger level
func SetGlobalOutput ¶
SetGlobalOutput sets the global logger output
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode represents different types of errors
const ( // Connection errors ErrorCodeConnectionFailed ErrorCode = "CONNECTION_FAILED" ErrorCodeConnectionTimeout ErrorCode = "CONNECTION_TIMEOUT" ErrorCodeConnectionLost ErrorCode = "CONNECTION_LOST" // Protocol errors ErrorCodeInvalidJSON ErrorCode = "INVALID_JSON" ErrorCodeProtocolViolation ErrorCode = "PROTOCOL_VIOLATION" ErrorCodeUnsupportedVersion ErrorCode = "UNSUPPORTED_VERSION" // Server errors ErrorCodeServerCrash ErrorCode = "SERVER_CRASH" ErrorCodeServerTimeout ErrorCode = "SERVER_TIMEOUT" ErrorCodeServerNotResponding ErrorCode = "SERVER_NOT_RESPONDING" // Tool errors ErrorCodeToolNotFound ErrorCode = "TOOL_NOT_FOUND" ErrorCodeToolExecutionFailed ErrorCode = "TOOL_EXECUTION_FAILED" ErrorCodeInvalidToolArgs ErrorCode = "INVALID_TOOL_ARGS" // Resource errors ErrorCodeResourceNotFound ErrorCode = "RESOURCE_NOT_FOUND" ErrorCodeResourceReadFailed ErrorCode = "RESOURCE_READ_FAILED" ErrorCodeInvalidResourceURI ErrorCode = "INVALID_RESOURCE_URI" // UI errors ErrorCodeUIRenderFailed ErrorCode = "UI_RENDER_FAILED" ErrorCodeKeyHandlingFailed ErrorCode = "KEY_HANDLING_FAILED" // System errors ErrorCodeProcessStartFailed ErrorCode = "PROCESS_START_FAILED" ErrorCodeSignalHandlingFailed ErrorCode = "SIGNAL_HANDLING_FAILED" )
func GetErrorCode ¶
GetErrorCode extracts the error code from an error
type Field ¶
type Field struct {
Key string
Value interface{}
}
Field represents a structured logging field
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer stores recent log entries in memory for viewing
func NewLogBuffer ¶
NewLogBuffer creates a new log buffer with the specified maximum size
func (*LogBuffer) GetEntries ¶
GetEntries returns a copy of all log entries
func (*LogBuffer) GetEntriesAsStrings ¶
GetEntriesAsStrings returns all log entries formatted as strings
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time
Level LogLevel
Component string
Message string
Fields []Field
}
LogEntry represents a single log entry
type LogLevel ¶
type LogLevel int
LogLevel represents different logging levels
func LogLevelFromString ¶
LogLevelFromString converts a string to a log level
type Logger ¶
type Logger interface {
Debug(msg string, fields ...Field)
Info(msg string, fields ...Field)
Warn(msg string, fields ...Field)
Error(msg string, fields ...Field)
Fatal(msg string, fields ...Field)
WithFields(fields ...Field) Logger
WithComponent(component string) Logger
SetLevel(level LogLevel)
SetOutput(w io.Writer)
}
Logger provides structured logging functionality
type MCPError ¶
type MCPError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
Cause error `json:"-"`
Stack []string `json:"stack,omitempty"`
}
MCPError represents a structured error with context
func (*MCPError) WithDetail ¶
WithDetail adds a detail to the error
type MCPLogEntry ¶
type MCPLogEntry struct {
Timestamp time.Time `json:"timestamp"`
Direction string `json:"direction"` // "→" (outgoing) or "←" (incoming)
MessageType MCPMessageType `json:"messageType"`
Method string `json:"method,omitempty"`
ID interface{} `json:"id,omitempty"`
Params interface{} `json:"params,omitempty"`
Result interface{} `json:"result,omitempty"`
Error interface{} `json:"error,omitempty"`
RawMessage string `json:"rawMessage"`
}
MCPLogEntry represents a single MCP protocol message
func (MCPLogEntry) DetailedString ¶
func (e MCPLogEntry) DetailedString() string
DetailedString provides enhanced formatting for TUI display
func (MCPLogEntry) GetFormattedJSON ¶
func (e MCPLogEntry) GetFormattedJSON() string
GetFormattedJSON returns the raw message formatted as pretty JSON
func (MCPLogEntry) String ¶
func (e MCPLogEntry) String() string
String formats the MCP log entry for display
type MCPLogger ¶
type MCPLogger struct {
// contains filtered or unexported fields
}
MCPLogger captures all MCP protocol communication
func NewMCPLogger ¶
NewMCPLogger creates a new MCP protocol logger
func (*MCPLogger) GetEntries ¶
func (ml *MCPLogger) GetEntries() []MCPLogEntry
GetEntries returns a copy of all MCP log entries
func (*MCPLogger) GetEntriesAsStrings ¶
GetEntriesAsStrings returns all MCP log entries formatted as strings
func (*MCPLogger) LogIncoming ¶
LogIncoming logs an incoming message from the MCP server
func (*MCPLogger) LogOutgoing ¶
LogOutgoing logs an outgoing message to the MCP server
type MCPMessageType ¶
type MCPMessageType string
MCPMessageType represents the type of MCP message
const ( MCPMessageRequest MCPMessageType = "REQUEST" MCPMessageResponse MCPMessageType = "RESPONSE" MCPMessageNotification MCPMessageType = "NOTIFICATION" MCPMessageError MCPMessageType = "ERROR" )