debug

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...Field)

Debug logs a debug message using the global logger

func Error

func Error(msg string, fields ...Field)

Error logs an error message using the global logger

func Fatal

func Fatal(msg string, fields ...Field)

Fatal logs a fatal message using the global logger and exits

func FormatError

func FormatError(err error) string

FormatError formats an error for display to users

func Info

func Info(msg string, fields ...Field)

Info logs an info message using the global logger

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

func InitializeLogging(level string, debugMode bool)

InitializeLogging sets up logging based on environment

func IsErrorCode

func IsErrorCode(err error, code ErrorCode) bool

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

func SetGlobalOutput(w io.Writer)

SetGlobalOutput sets the global logger output

func Shutdown

func Shutdown()

Shutdown gracefully shuts down the global logger

func Warn

func Warn(msg string, fields ...Field)

Warn logs a warning message using the global logger

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

func GetErrorCode(err error) ErrorCode

GetErrorCode extracts the error code from an error

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field represents a structured logging field

func F

func F(key string, value interface{}) Field

F creates a new field (convenience function)

type LogBuffer

type LogBuffer struct {
	// contains filtered or unexported fields
}

LogBuffer stores recent log entries in memory for viewing

func GetLogBuffer

func GetLogBuffer() *LogBuffer

GetLogBuffer returns the global log buffer

func NewLogBuffer

func NewLogBuffer(maxSize int) *LogBuffer

NewLogBuffer creates a new log buffer with the specified maximum size

func (*LogBuffer) Add

func (lb *LogBuffer) Add(level LogLevel, component, message string, fields []Field)

Add adds a new log entry to the buffer

func (*LogBuffer) Clear

func (lb *LogBuffer) Clear()

Clear removes all entries from the buffer

func (*LogBuffer) GetEntries

func (lb *LogBuffer) GetEntries() []LogEntry

GetEntries returns a copy of all log entries

func (*LogBuffer) GetEntriesAsStrings

func (lb *LogBuffer) GetEntriesAsStrings() []string

GetEntriesAsStrings returns all log entries formatted as strings

func (*LogBuffer) Size

func (lb *LogBuffer) Size() int

Size returns the current number of entries in the buffer

type LogEntry

type LogEntry struct {
	Timestamp time.Time
	Level     LogLevel
	Component string
	Message   string
	Fields    []Field
}

LogEntry represents a single log entry

func (LogEntry) String

func (e LogEntry) String() string

String formats the log entry as a string

type LogLevel

type LogLevel int

LogLevel represents different logging levels

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal
)

func LogLevelFromString

func LogLevelFromString(s string) LogLevel

LogLevelFromString converts a string to a log level

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the 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

func Component

func Component(name string) Logger

Component returns a logger with a component name

func NewLogger

func NewLogger() Logger

NewLogger creates a new logger

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 NewError

func NewError(code ErrorCode, message string) *MCPError

NewError creates a new MCP error

func WrapError

func WrapError(err error, code ErrorCode, message string) *MCPError

WrapError wraps an existing error with MCP error context

func (*MCPError) Error

func (e *MCPError) Error() string

Error implements the error interface

func (*MCPError) Unwrap

func (e *MCPError) Unwrap() error

Unwrap returns the underlying cause

func (*MCPError) WithDetail

func (e *MCPError) WithDetail(key string, value interface{}) *MCPError

WithDetail adds a detail to the error

func (*MCPError) WithStack

func (e *MCPError) WithStack(stack []string) *MCPError

WithStack adds stack trace information

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 GetMCPLogger

func GetMCPLogger() *MCPLogger

GetMCPLogger returns the global MCP logger

func NewMCPLogger

func NewMCPLogger(maxSize int) *MCPLogger

NewMCPLogger creates a new MCP protocol logger

func (*MCPLogger) Clear

func (ml *MCPLogger) Clear()

Clear removes all entries from the logger

func (*MCPLogger) GetEntries

func (ml *MCPLogger) GetEntries() []MCPLogEntry

GetEntries returns a copy of all MCP log entries

func (*MCPLogger) GetEntriesAsStrings

func (ml *MCPLogger) GetEntriesAsStrings() []string

GetEntriesAsStrings returns all MCP log entries formatted as strings

func (*MCPLogger) GetStats

func (ml *MCPLogger) GetStats() map[string]int

GetStats returns statistics about the logged messages

func (*MCPLogger) LogIncoming

func (ml *MCPLogger) LogIncoming(rawMessage string, parsedMessage interface{})

LogIncoming logs an incoming message from the MCP server

func (*MCPLogger) LogOutgoing

func (ml *MCPLogger) LogOutgoing(rawMessage string, parsedMessage interface{})

LogOutgoing logs an outgoing message to the MCP server

func (*MCPLogger) Size

func (ml *MCPLogger) Size() int

Size returns the current number of entries

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL