logger

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 19 Imported by: 0

README

Logger Package

A simple, debug-style logging framework for Go that follows the pattern matching syntax of the debug npm package.

Features

  • Namespace-based logging: Each logger has a namespace (e.g., workflow:compiler, cli:audit)
  • Pattern matching: Enable/disable loggers using wildcards and exclusions via the DEBUG environment variable
  • Printf interface: Standard printf-style formatting
  • Time diff display: Shows time elapsed since last log call (like debug npm package)
  • Automatic color coding: Each namespace gets a unique color when stderr is a TTY
  • Zero overhead: Logger enabled state is computed once at construction time
  • Thread-safe: Safe for concurrent use
  • Per-ServerID Logs: Separate log files for each backend MCP server for easier troubleshooting

Per-ServerID Logging

The logger package supports creating separate log files for each backend MCP server (identified by serverID). This makes it much easier to troubleshoot specific servers without sifting through unified logs.

How It Works
  • Each serverID gets its own log file: {serverID}.log in the log directory
  • Logs are also written to the main mcp-gateway.log for a unified view
  • Concurrent writes to different serverID logs are handled safely
  • Fallback to unified logging if per-serverID logging cannot be initialized
Usage
import "github.com/github/gh-aw-mcpg/internal/logger"

// Log to both the unified log and the server-specific log
logger.LogInfoToServer("github", "backend", "Server started successfully")
logger.LogWarnToServer("slack", "backend", "Connection timeout")
logger.LogErrorToServer("github", "backend", "Failed to authenticate: %v", err)
logger.LogDebugToServer("notion", "backend", "Processing request: %v", req)
Log File Structure

When per-serverID logging is enabled, the log directory contains:

/tmp/gh-aw/mcp-logs/
├── mcp-gateway.log    # Unified log with all messages
├── github.log          # Only logs for the "github" server
├── slack.log           # Only logs for the "slack" server
└── notion.log          # Only logs for the "notion" server

Each server-specific log file contains only the messages related to that serverID, making it easier to debug issues with individual backend servers.

Initialization

Per-serverID logging is automatically initialized when the gateway starts:

// In internal/cmd/root.go
logger.InitServerFileLogger(logDir)
defer logger.CloseAllLoggers()
Benefits
  • Easier Debugging: View all logs for a specific server in isolation
  • Reduced Noise: No need to filter through logs from other servers
  • Better Troubleshooting: Quickly identify which server is having issues
  • Concurrent Access: Safe to log to multiple servers simultaneously
  • Backward Compatible: Falls back gracefully if initialization fails

Usage

Basic Usage
package main

import "github.com/github/gh-aw-mcpg/internal/logger"

var log = logger.New("myapp:feature")

func main() {
    log.Printf("Starting application with config: %s", config)
    log.Print("Multiple", " ", "arguments")
}

Output shows namespace, message, and time diff:

myapp:feature Starting application with config: production +0ns
myapp:feature Multiple arguments +125ms
Avoiding Expensive Operations

Check if a logger is enabled before performing expensive operations:

if log.Enabled() {
    // Do expensive work only if logging is enabled
    result := expensiveOperation()
    log.Printf("Result: %v", result)
}
Time Diff Display

Like the debug npm package, each log shows the time elapsed since the last log call:

log.Printf("Starting task")
// ... do some work ...
log.Printf("Task completed")  // Shows +2.5s (or +500ms, +100µs, etc.)

DEBUG Environment Variable

Control which loggers are enabled using the DEBUG environment variable with patterns:

Examples
# Enable all loggers
DEBUG=*

# Enable all loggers in the 'workflow' namespace
DEBUG=workflow:*

# Enable specific loggers
DEBUG=workflow:compiler,cli:audit

# Enable all except specific loggers
DEBUG=*,-workflow:compiler

# Enable namespace but exclude specific patterns
DEBUG=workflow:*,-workflow:compiler:cache

# Multiple patterns with exclusions
DEBUG=workflow:*,cli:*,-workflow:test

Color Support

Colors are automatically assigned to each namespace when:

  • Stderr is a TTY (terminal)
  • DEBUG_COLORS is not set to 0

Each namespace gets a consistent color based on a hash of its name. This makes it easy to visually distinguish between different loggers.

Disabling Colors
# Disable colors
DEBUG_COLORS=0 DEBUG=* gh aw compile workflow.md

# Colors are automatically disabled when piping output
DEBUG=* gh aw compile workflow.md 2>&1 | tee output.log
Pattern Syntax
  • * - Matches all loggers
  • namespace:* - Matches all loggers with the given prefix
  • *:suffix - Matches all loggers with the given suffix
  • prefix:*:suffix - Matches loggers with both prefix and suffix
  • -pattern - Excludes loggers matching the pattern (takes precedence)
  • pattern1,pattern2 - Multiple patterns separated by commas

Design Decisions

Logger Enabled State

The enabled state is computed once at logger construction time based on the DEBUG environment variable. This means:

  • Zero overhead for disabled loggers (simple boolean check)
  • DEBUG changes after the process starts won't affect existing loggers
Time Diff Tracking

Each logger tracks the time of its last log call to display elapsed time, similar to the debug npm package. This helps identify performance bottlenecks and understand timing relationships between log messages.

Output Destination

Log output goes to two destinations:

  • stderr - Colorized output with time diffs (controlled by DEBUG environment variable)
  • file logger - Text-only output without colors or time diffs (always logged when enabled)

This dual output approach allows:

  • Real-time debugging with colored, timestamped output during development
  • Persistent, parseable log files for production troubleshooting
  • All debug logs are captured to file, making it easier to diagnose issues after the fact
Printf Interface

The logger provides a familiar printf-style interface that Go developers expect:

  • Printf(format, args...) - Formatted output (always adds newline)
  • Print(args...) - Simple concatenation (always adds newline)

Example Patterns

File-based Namespaces
// In pkg/workflow/compiler.go
var log = logger.New("workflow:compiler")

// In pkg/cli/audit.go  
var log = logger.New("cli:audit")

// In pkg/parser/frontmatter.go
var log = logger.New("parser:frontmatter")

Enable with:

DEBUG=workflow:* go run main.go      # Only workflow package
DEBUG=cli:*,parser:* go run main.go  # CLI and parser packages
DEBUG=* go run main.go                # Everything
Feature-based Namespaces
var compileLog = logger.New("compile")
var parseLog = logger.New("parse")
var validateLog = logger.New("validate")

Implementation Notes

  • The DEBUG environment variable is read once when the package is initialized
  • Thread-safe using sync.Mutex for time tracking
  • Simple pattern matching without regex (prefix, suffix, and middle wildcards only)
  • Exclusion patterns (prefixed with -) take precedence over inclusion patterns
  • Time diff formatted like debug npm package (ns, µs, ms, s, m, h)
  • Colors assigned using FNV-1a hash for consistent namespace-to-color mapping
  • Color palette chosen for readability on both light and dark terminals
  • Uses ANSI 256-color codes for better compatibility

Documentation

Overview

Package logger provides the gateway logging implementations.

The package exposes three parallel global sink APIs:

  • LogInfo / LogWarn / LogError / LogDebug for unified file/stdout logs
  • LogInfoToMarkdown / LogWarnToMarkdown / LogErrorToMarkdown / LogDebugToMarkdown for markdown preview logs
  • LogInfoToServer / LogWarnToServer / LogErrorToServer / LogDebugToServer for per-server logs

These APIs target different sinks and can be used together when a message should appear in multiple outputs. The unified file and markdown helper families share a common sink-dispatch path so new sink fan-out behavior stays centralized.

Per-type setup and error-handler functions

Each logger type has its own setup* and handleError* functions (e.g. setupFileLogger / handleFileLoggerError, setupMarkdownLogger / handleMarkdownLoggerError). These are intentionally not collapsed into a single generic helper because each type has unique initialization behaviour:

  • JSONLLogger has no fallback path (a failure returns an error directly).
  • ToolsLogger writes a one-time header and closes the file immediately after opening, so its setup function owns that lifecycle step.
  • FileLogger, MarkdownLogger, and RPCLogger each open a persistent file and wire up different formatters.

The per-type functions are bundled via the loggerFactory[T] generic defined in global_state.go, which handles the shared open-file / call-setup / call-onError flow.

Package logger provides structured logging for the MCP Gateway.

This file contains generic helper functions for managing global logger state with proper mutex handling. These helpers encapsulate common patterns for initializing and closing global loggers (FileLogger, JSONLLogger, MarkdownLogger) to reduce code duplication while maintaining thread safety.

Functions in this file follow a consistent pattern:

- init*: Initialize a global logger with proper locking and cleanup of any existing logger - close*: Close and clear a global logger with proper locking

The unexported helpers (withMutexLock, withGlobalLogger, initGlobalLogger, closeGlobalLogger) are used internally by the logger package and should not be called directly by external code. Use the public Init* and Close* functions instead. CloseAllLoggers is the public entry point for closing all global loggers at once.

Package logger provides structured logging for the MCP Gateway.

This file contains formatting and payload helper functions for RPC message logs.

Text Format: Compact, single-line format optimized for grep and command-line tools

Example: "github→tools/list 1234b {...}"

Markdown Format: Human-readable with syntax highlighting, suitable for documentation

Example: "**github**→`tools/list`\n\n```json\n{...}\n```"

Both formats use directional arrows (→ for outbound, ← for inbound) and support special handling for tools/call methods by extracting and displaying tool names.

Package logger provides structured logging for the MCP Gateway.

This file contains RPC message logging coordination, managing the flow of messages across multiple output formats (text, markdown, JSONL).

File Organization:

- rpc_logger.go (this file): Coordination of RPC logging across formats - rpc_format.go: Formatting and payload helper functions

The package supports logging RPC messages in three formats:

1. Text logs: Compact single-line format for grep-friendly searching 2. Markdown logs: Human-readable format with syntax highlighting 3. JSONL logs: Machine-readable format for structured analysis

Example:

logger.LogRPCRequest(logger.RPCDirectionOutbound, "github", "tools/list", payload, nil, nil)
logger.LogRPCResponse(logger.RPCDirectionInbound, "github", responsePayload, nil, nil, nil)

Package logger provides structured logging for the MCP Gateway.

This file implements logging of MCP server tools to a JSON file (tools.json). It maintains a mapping of server IDs to their available tools with names and descriptions.

Index

Constants

View Source
const (
	// EnvDebug is the environment variable for debug logging patterns.
	// Supports patterns like "*", "namespace:*", "ns1,ns2", "ns:*,-ns:skip"
	EnvDebug = "DEBUG"

	// EnvDebugColors controls colored output in debug logs.
	// Set to "0" to disable colors.
	EnvDebugColors = "DEBUG_COLORS"
)

Environment variable names for logging configuration

View Source
const (
	// MaxPayloadPreviewLengthText is the maximum number of characters to include in text log preview (10KB)
	MaxPayloadPreviewLengthText = 10 * 1024 // 10KB
	// MaxPayloadPreviewLengthMarkdown is the maximum number of characters to include in markdown log preview
	MaxPayloadPreviewLengthMarkdown = 512
)

Variables

This section is empty.

Functions

func CloseAllLoggers added in v0.2.20

func CloseAllLoggers() error

CloseAllLoggers closes all global loggers in a single call. Returns the first error encountered, but attempts to close every logger.

func Discard

func Discard() *slog.Logger

Discard returns a slog.Logger that discards all output

func InitFileLogger

func InitFileLogger(logDir, fileName string) error

InitFileLogger initializes the global file logger If the log directory doesn't exist and can't be created, falls back to stderr

func InitGatewayLoggers added in v0.2.18

func InitGatewayLoggers(logDir string)

InitGatewayLoggers initializes the standard set of gateway loggers for the given log directory. Failures are printed as warnings but do not abort startup.

func InitJSONLLogger

func InitJSONLLogger(logDir, fileName string) error

InitJSONLLogger initializes the global JSONL logger

func InitMarkdownLogger

func InitMarkdownLogger(logDir, fileName string) error

InitMarkdownLogger initializes the global markdown logger

func InitObservedURLDomainsLogger added in v0.3.29

func InitObservedURLDomainsLogger(logDir, fileName string) error

InitObservedURLDomainsLogger initializes observed-url-domains.json logger.

func InitProxyLoggers added in v0.2.18

func InitProxyLoggers(logDir string)

InitProxyLoggers initializes the subset of loggers used by the proxy command. Failures are printed as warnings but do not abort startup.

func InitServerFileLogger added in v0.0.102

func InitServerFileLogger(logDir string) error

InitServerFileLogger initializes the global server file logger

func InitToolsLogger added in v0.1.1

func InitToolsLogger(logDir, fileName string) error

InitToolsLogger initializes the global tools logger If the log directory doesn't exist and can't be created, falls back to no-op

func LogDebug

func LogDebug(category, format string, args ...interface{})

LogDebug logs a debug message to the unified file logger sink. The underlying filename depends on logger initialization. For destination-specific logging use LogDebugToMarkdown or LogDebugToServer.

func LogDebugToMarkdown added in v0.3.7

func LogDebugToMarkdown(category, format string, args ...interface{})

LogDebugToMarkdown logs to both regular and markdown loggers.

func LogDebugToServer added in v0.3.7

func LogDebugToServer(serverID, category, format string, args ...interface{})

LogDebugToServer logs a debug message to the server-specific log file.

func LogDifcFilteredItem added in v0.1.17

func LogDifcFilteredItem(entry *JSONLFilteredItem)

LogDifcFilteredItem writes a DIFC filter event to the JSONL log.

func LogError

func LogError(category, format string, args ...interface{})

LogError logs an error message to the unified file logger sink. The underlying filename depends on logger initialization. For destination-specific logging use LogErrorToMarkdown or LogErrorToServer.

func LogErrorToMarkdown added in v0.3.7

func LogErrorToMarkdown(category, format string, args ...interface{})

LogErrorToMarkdown logs to both regular and markdown loggers.

func LogErrorToServer added in v0.3.7

func LogErrorToServer(serverID, category, format string, args ...interface{})

LogErrorToServer logs an error message to the server-specific log file.

func LogInfo

func LogInfo(category, format string, args ...interface{})

LogInfo logs an informational message to the unified file logger sink. The underlying filename depends on logger initialization. For destination-specific logging use LogInfoToMarkdown or LogInfoToServer.

func LogInfoToMarkdown added in v0.3.7

func LogInfoToMarkdown(category, format string, args ...interface{})

LogInfoToMarkdown logs to both regular and markdown loggers.

func LogInfoToServer added in v0.3.7

func LogInfoToServer(serverID, category, format string, args ...interface{})

LogInfoToServer logs an informational message to the server-specific log file.

func LogMarshaledForDebug added in v0.2.25

func LogMarshaledForDebug(value interface{}, onMarshalSuccess func(string), onMarshalFailure func(error))

LogMarshaledForDebug marshals value for debug logging and dispatches to the provided callbacks for success or marshal failure paths.

func LogMarshaledForDebugf added in v0.3.27

func LogMarshaledForDebugf(
	value interface{},
	onMarshalSuccessf func(string, ...interface{}),
	successFormat string,
	onMarshalFailuref func(string, ...interface{}),
	failureFormat string,
	args ...interface{},
)

LogMarshaledForDebugf marshals value for debug logging and dispatches to formatted logging functions for success or marshal failure paths.

func LogObservedURLDomains added in v0.3.29

func LogObservedURLDomains(serverID string, domains []string)

LogObservedURLDomains appends newly observed domains for a server.

func LogRPCMessage

func LogRPCMessage(info *RPCMessageInfo)

LogRPCMessage logs a generic RPC message with custom info. It uses the withGlobalLogger helper from global_helpers.go to handle mutex locking and nil-checking.

func LogRPCMessageJSONL

func LogRPCMessageJSONL(direction RPCMessageDirection, messageType RPCMessageType, serverID, method string, payloadBytes []byte, err error)

LogRPCMessageJSONL logs an RPC message to the global JSONL logger

func LogRPCMessageJSONLWithTags added in v0.1.10

func LogRPCMessageJSONLWithTags(direction RPCMessageDirection, messageType RPCMessageType, serverID, method string, payloadBytes []byte, err error, agentSecrecy, agentIntegrity []string)

LogRPCMessageJSONLWithTags logs an RPC message to the global JSONL logger with optional agent tag snapshots. It uses the withGlobalLogger helper from global_helpers.go to handle mutex locking and nil-checking.

func LogRPCRequest

func LogRPCRequest(direction RPCMessageDirection, serverID, method string, payload []byte, agentSecrecy, agentIntegrity []string)

LogRPCRequest logs an RPC request message to text, markdown, and JSONL logs. agentSecrecy and agentIntegrity are optional and only affect JSONL output.

func LogRPCResponse

func LogRPCResponse(direction RPCMessageDirection, serverID string, payload []byte, err error, agentSecrecy, agentIntegrity []string)

LogRPCResponse logs an RPC response message to text, markdown, and JSONL logs. agentSecrecy and agentIntegrity are optional and only affect JSONL output.

func LogToolsForServer added in v0.1.1

func LogToolsForServer(serverID string, tools []ToolInfo)

LogToolsForServer logs the tools for a specific server. It uses the withGlobalLogger helper from global_helpers.go to handle mutex locking and nil-checking.

func LogUnrecognizedEndpointPassthrough added in v0.3.25

func LogUnrecognizedEndpointPassthrough(method, path string)

LogUnrecognizedEndpointPassthrough writes the proxy's unrecognized-endpoint passthrough event to the standard text log, markdown artifact log, and JSONL log.

func LogWarn

func LogWarn(category, format string, args ...interface{})

LogWarn logs a warning message to the unified file logger sink. The underlying filename depends on logger initialization. For destination-specific logging use LogWarnToMarkdown or LogWarnToServer.

func LogWarnToMarkdown added in v0.3.7

func LogWarnToMarkdown(category, format string, args ...interface{})

LogWarnToMarkdown logs to both regular and markdown loggers.

func LogWarnToServer added in v0.3.7

func LogWarnToServer(serverID, category, format string, args ...interface{})

LogWarnToServer logs a warning message to the server-specific log file.

func NewSlogLogger

func NewSlogLogger(namespace string) *slog.Logger

NewSlogLogger creates a new slog.Logger that uses gh-aw's logger package This allows integration with libraries that expect slog.Logger

func NewSlogLoggerWithHandler

func NewSlogLoggerWithHandler(logger *Logger) *slog.Logger

NewSlogLoggerWithHandler creates a new slog.Logger using an existing Logger instance

func SetURLDomainAuditEnabled added in v0.3.29

func SetURLDomainAuditEnabled(enabled bool)

SetURLDomainAuditEnabled toggles URL domain observation for middleware and guards.

func ShutdownWarn added in v0.4.2

func ShutdownWarn(format string, args ...interface{})

ShutdownWarn logs a shutdown warning message to stderr (via log.Printf with "Warning: " prefix) and to the shutdown warning log sink (via LogWarn with "shutdown" category).

func StartupInfo added in v0.2.18

func StartupInfo(format string, args ...interface{})

StartupInfo logs a startup informational message to stderr (via log.Printf) and to the startup markdown/file log sink (via LogInfoToMarkdown with "startup" category). This eliminates the need to call log.Printf and LogInfoToMarkdown separately for the same message.

func StartupWarn added in v0.2.18

func StartupWarn(format string, args ...interface{})

StartupWarn logs a startup warning message to stderr (via log.Printf with "Warning: " prefix) and to the startup warning log sink (via LogWarn with "startup" category). This eliminates the need to call log.Printf and LogWarn separately for the same message.

func URLDomainAuditEnabled added in v0.3.29

func URLDomainAuditEnabled() bool

URLDomainAuditEnabled reports whether URL domain observation is enabled.

Types

type FileLogger

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

FileLogger manages logging to a file with fallback to stderr

func (*FileLogger) Close

func (fl *FileLogger) Close() error

Close closes the log file

func (*FileLogger) GetWriter

func (fl *FileLogger) GetWriter() io.Writer

GetWriter returns the underlying io.Writer for the file logger

func (*FileLogger) Log

func (fl *FileLogger) Log(level LogLevel, category, format string, args ...interface{})

Log writes a log message with the specified level and category

type FilteredItemLogEntry added in v0.1.19

type FilteredItemLogEntry struct {
	ServerID          string   `json:"server_id"`
	ToolName          string   `json:"tool_name"`
	Description       string   `json:"description"`
	Reason            string   `json:"reason"`
	SecrecyTags       []string `json:"secrecy_tags"`
	IntegrityTags     []string `json:"integrity_tags"`
	AuthorAssociation string   `json:"author_association,omitempty"`
	AuthorLogin       string   `json:"author_login,omitempty"`
	HTMLURL           string   `json:"html_url,omitempty"`
	Number            string   `json:"number,omitempty"`
	SHA               string   `json:"sha,omitempty"`
}

FilteredItemLogEntry holds the data fields for a DIFC-filtered item. It is used for both text log output ([DIFC-FILTERED] JSON lines) and as the embedded payload in JSONLFilteredItem for JSONL log output.

type JSONLFilteredItem added in v0.1.17

type JSONLFilteredItem struct {
	Timestamp string `json:"timestamp"`
	Event     string `json:"event"`   // Always "difc_filtered"
	Schema    string `json:"_schema"` // "difc-filtered/v2"
	FilteredItemLogEntry
}

JSONLFilteredItem represents a DIFC-filtered item logged to the JSONL stream. These entries appear alongside RPC messages so filter events are visible in context with the request/response that triggered them. It embeds FilteredItemLogEntry so that adding a data field requires only a single edit rather than parallel edits in two structs.

type JSONLLogger

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

JSONLLogger manages logging RPC messages to a JSONL file (one JSON object per line)

func (*JSONLLogger) Close

func (jl *JSONLLogger) Close() error

Close closes the JSONL log file

func (*JSONLLogger) LogMessage

func (jl *JSONLLogger) LogMessage(entry *JSONLRPCMessage) error

LogMessage logs an RPC message to the JSONL file

type JSONLRPCMessage

type JSONLRPCMessage struct {
	Timestamp      string          `json:"timestamp"`
	Event          string          `json:"event"`     // "rpc_request" or "rpc_response"
	Schema         string          `json:"_schema"`   // "rpc-message/v2"
	Direction      string          `json:"direction"` // "IN" or "OUT"
	ServerID       string          `json:"server_id"`
	Method         string          `json:"method,omitempty"`
	Error          string          `json:"error,omitempty"`
	AgentSecrecy   []string        `json:"agent_secrecy,omitempty"`
	AgentIntegrity []string        `json:"agent_integrity,omitempty"`
	Payload        json.RawMessage `json:"payload"` // Full sanitized payload as raw JSON
}

JSONLRPCMessage represents a single RPC message log entry in JSONL format

type JSONLUnrecognizedEndpointPassthrough added in v0.3.25

type JSONLUnrecognizedEndpointPassthrough struct {
	Timestamp string `json:"timestamp"`
	Event     string `json:"event"`
	Schema    string `json:"_schema"`
	Method    string `json:"method"`
	Path      string `json:"path"`
	Action    string `json:"action"`
	Note      string `json:"note"`
}

JSONLUnrecognizedEndpointPassthrough records when the proxy forwards an unrecognized endpoint with empty DIFC labels.

type LogLevel

type LogLevel string

LogLevel represents the severity of a log message

const (
	LogLevelInfo  LogLevel = "INFO"
	LogLevelWarn  LogLevel = "WARN"
	LogLevelError LogLevel = "ERROR"
	LogLevelDebug LogLevel = "DEBUG"
)

type Logger

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

Logger represents a debug logger for a specific namespace.

func ForFile added in v0.4.2

func ForFile() *Logger

ForFile creates a new Logger with a namespace automatically derived from the calling file's path. The namespace follows the "package:filename" convention where package is the last directory component of the file path and filename is the Go source file name without the .go extension. This eliminates manually maintained namespace strings.

Example: a call from internal/server/unified.go yields namespace "server:unified".

func New

func New(namespace string) *Logger

New creates a new Logger for the given namespace. The enabled state is computed at construction time based on the DEBUG environment variable. DEBUG syntax follows https://www.npmjs.com/package/debug patterns:

DEBUG=*              - enables all loggers
DEBUG=namespace:*    - enables all loggers in a namespace
DEBUG=ns1,ns2        - enables specific namespaces
DEBUG=ns:*,-ns:skip  - enables namespace but excludes specific patterns

Colors are automatically assigned to each namespace if DEBUG_COLORS != "0" and stderr is a TTY.

func (*Logger) Enabled

func (l *Logger) Enabled() bool

Enabled returns whether this logger is enabled

func (*Logger) Print

func (l *Logger) Print(args ...any)

Print prints a message if the logger is enabled. A newline is always added at the end. Time diff since last log is displayed like the debug npm package. Also writes to the file logger in text-only format.

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...any)

Printf prints a formatted message if the logger is enabled. A newline is always added at the end. Time diff since last log is displayed like the debug npm package. Also writes to the file logger in text-only format.

type MarkdownLogger

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

MarkdownLogger manages logging to a markdown file for GitHub workflow previews

func (*MarkdownLogger) Close

func (ml *MarkdownLogger) Close() error

Close closes the log file and writes the closing details tag

func (*MarkdownLogger) Log

func (ml *MarkdownLogger) Log(level LogLevel, category, format string, args ...interface{})

Log writes a log message in markdown format with emoji bullet points

type ObservedURLDomainsLogger added in v0.3.29

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

ObservedURLDomainsLogger manages unique observed URL domains grouped by server ID.

func (*ObservedURLDomainsLogger) Close added in v0.3.29

func (l *ObservedURLDomainsLogger) Close() error

func (*ObservedURLDomainsLogger) LogDomains added in v0.3.29

func (l *ObservedURLDomainsLogger) LogDomains(serverID string, domains []string) error

LogDomains logs unique domains for a server ID.

type RPCMessageDirection

type RPCMessageDirection string

RPCMessageDirection represents whether the message is inbound or outbound

const (
	// RPCDirectionInbound represents messages coming into the gateway
	RPCDirectionInbound RPCMessageDirection = "IN"
	// RPCDirectionOutbound represents messages going out from the gateway
	RPCDirectionOutbound RPCMessageDirection = "OUT"
)

type RPCMessageInfo

type RPCMessageInfo struct {
	Direction   RPCMessageDirection // IN or OUT
	MessageType RPCMessageType      // REQUEST or RESPONSE
	ServerID    string              // Backend server ID or "client" for client messages
	Method      string              // RPC method name (for requests)
	PayloadSize int                 // Size of the payload in bytes
	Payload     string              // First N characters of payload (sanitized)
	Error       string              // Error message if any (for responses)
}

RPCMessageInfo contains information about an RPC message for logging

type RPCMessageType

type RPCMessageType string

RPCMessageType represents the direction of an RPC message

const (
	// RPCMessageRequest represents an outbound request or inbound client request
	RPCMessageRequest RPCMessageType = "REQUEST"
	// RPCMessageResponse represents an inbound response from backend or outbound response to client
	RPCMessageResponse RPCMessageType = "RESPONSE"
)

func (RPCMessageType) JSONLEvent added in v0.3.19

func (t RPCMessageType) JSONLEvent() string

JSONLEvent returns the standardized JSONL event name for this RPC message type.

type ServerFileLogger added in v0.0.102

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

ServerFileLogger manages per-serverID log files

func (*ServerFileLogger) Close added in v0.0.102

func (sfl *ServerFileLogger) Close() error

Close closes all server log files

func (*ServerFileLogger) Log added in v0.0.102

func (sfl *ServerFileLogger) Log(serverID string, level LogLevel, category, format string, args ...interface{})

Log writes a log message to the server-specific log file

type SlogHandler

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

SlogHandler implements slog.Handler by wrapping a gh-aw Logger This allows integration with libraries that expect slog.Logger

func NewSlogHandler

func NewSlogHandler(logger *Logger) *SlogHandler

NewSlogHandler creates a new slog.Handler that wraps a gh-aw Logger

func (*SlogHandler) Enabled

func (h *SlogHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level. We enable all levels when our logger is enabled.

func (*SlogHandler) Handle

func (h *SlogHandler) Handle(_ context.Context, r slog.Record) error

Handle handles the Record. It will only be called when Enabled returns true.

func (*SlogHandler) WithAttrs

func (h *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments. This implementation does not persist attributes.

func (*SlogHandler) WithGroup

func (h *SlogHandler) WithGroup(name string) slog.Handler

WithGroup returns a new Handler with the given group appended to the receiver's existing groups. This implementation does not persist groups.

type ToolInfo added in v0.1.1

type ToolInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

ToolInfo represents information about a single tool

type ToolsData added in v0.1.1

type ToolsData struct {
	// Map of serverID to array of tools
	Servers map[string][]ToolInfo `json:"servers"`
}

ToolsData represents the structure of tools.json

type ToolsLogger added in v0.1.1

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

ToolsLogger manages logging of MCP server tools to a JSON file

func (*ToolsLogger) Close added in v0.1.1

func (tl *ToolsLogger) Close() error

Close is a no-op for ToolsLogger (implements closableLogger interface)

func (*ToolsLogger) LogTools added in v0.1.1

func (tl *ToolsLogger) LogTools(serverID string, tools []ToolInfo) error

LogTools logs the tools for a specific server

Jump to

Keyboard shortcuts

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