logs

package
v0.73.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogLevelTrace = "trace"
	LogLevelDebug = "debug"
	LogLevelInfo  = "info"
	LogLevelWarn  = "warn"
	LogLevelError = "error"
)

Log level constants

Variables

This section is empty.

Functions

func ChildOutputField added in v0.68.0

func ChildOutputField() zap.Field

ChildOutputField stamps a record whose payload is a child process's own output (stderr lines, launcher-pumped stdout/stderr, docker CLI output). Every producer that writes child text into the per-server log — always as a field VALUE, never the message (rule 1) — attaches it, so the attributed reader can apply the child-output subject rule (rule 3).

func CleanupTestWriter

func CleanupTestWriter(file *os.File) error

CleanupTestWriter removes temporary test files

func CreateCLIUpstreamServerLogger

func CreateCLIUpstreamServerLogger(config *config.LogConfig, serverName string) (*zap.Logger, error)

CreateCLIUpstreamServerLogger creates a logger for CLI debugging that outputs to console

func CreateHTTPLogger

func CreateHTTPLogger(config *config.LogConfig) (*zap.Logger, error)

CreateHTTPLogger creates a logger specifically for HTTP API requests

func CreateRotatingWriteSyncer added in v0.23.0

func CreateRotatingWriteSyncer(config *config.LogConfig) (zapcore.WriteSyncer, error)

CreateRotatingWriteSyncer creates a rotation-backed file sink for a log config.

func CreateTestWriter

func CreateTestWriter() (io.Writer, *os.File, error)

CreateTestWriter creates a writer for testing that captures both file and memory output

func CreateUpstreamServerLogger

func CreateUpstreamServerLogger(config *config.LogConfig, serverName string) (*zap.Logger, error)

CreateUpstreamServerLogger creates a logger for a specific upstream server. The caller cannot release its file sink; prefer NewUpstreamServerLogger wherever the logger has an owner with a teardown path.

func DefaultLogConfig

func DefaultLogConfig() *config.LogConfig

DefaultLogConfig returns default logging configuration

func EnsureLogDir

func EnsureLogDir(logDir string) error

EnsureLogDir creates the log directory if it doesn't exist

func GetLogDir

func GetLogDir() (string, error)

GetLogDir returns the standard log directory for the current OS

func GetLogFilePath

func GetLogFilePath(filename string) (string, error)

GetLogFilePath returns the full path for a log file in the standard log directory

func GetLogFilePathWithDir

func GetLogFilePathWithDir(logDir, filename string) (string, error)

GetLogFilePathWithDir returns the full path for a log file in a custom log directory

func NewUpstreamServerLogger added in v0.66.1

func NewUpstreamServerLogger(config *config.LogConfig, serverName string) (*zap.Logger, io.Closer, error)

NewUpstreamServerLogger creates a logger for a specific upstream server and returns the closer of its file sink. Close it whenever the server is torn down or disconnected (issue #1266: an unclosed sink held one open handle per server for the life of the process, and on Windows pinned the file); a later write reopens the sink, so closing it on every disconnect is safe.

func ReadUpstreamServerLogTail

func ReadUpstreamServerLogTail(config *config.LogConfig, serverName string, lines int) ([]string, error)

ReadUpstreamServerLogTail reads the last N lines from an upstream server log file

func ReadUpstreamServerLogTailAttributed added in v0.68.0

func ReadUpstreamServerLogTailAttributed(config *config.LogConfig, serverName string, lines int) ([]string, error)

ReadUpstreamServerLogTailAttributed reads the last N records of an upstream server log that are attributable to serverName (Spec 105 FR-007, research D8). Attribution is decided per record BEFORE the tail limit, so an interleaved co-owner record never displaces an attributable one from the returned window, and the returned length is the authorized tail length. Records with no accepted stamp, records stamped for another server and records failing the subject-evidence rule are withheld. Administrators use ReadUpstreamServerLogTail (whole file, byte-identical to pre-105).

The scan starts at scopedBackwardStartOffset, at most scopedBackwardReadBudget bytes before EOF (codex round 16 finding 2): scanning from byte 0 made a request's cost proportional to whatever a hidden co-owner had written earlier in this shared file — a response-time side channel disclosing its volume, which SC-005's non-disclosing-refusal definition (status, body AND timing class) forbids. Below the budget (the common case) this reads and returns exactly what a whole-file scan from byte 0 would; past it, a request whose own most recent `lines` records sit further back returns fewer than `lines` records rather than reading further — bounded and fail-closed, not incorrect. The append-ordering this relies on (newest records nearest EOF), the boundary/subject-evidence rules (readBoundedLine, recordAttributableTo) and the per-record cap are all unchanged; only where the scan starts is new.

func RedactContainerMentions added in v0.68.0

func RedactContainerMentions(s string) string

RedactContainerMentions blanks every container id, canonical container name and Docker name-conflict phrase in s. The MCP status surface (`upstream_servers` tail_log / list `connection_status.last_error`, and the health detail derived from it) renders a connect error that re-emits the child's stderr — on a `docker run` name collision that text names the colliding container, which belongs to another server (`a/b` and `a-b` generate the same name). A scoped caller gets the same redaction whether or not a co-owner exists (FR-007: uniform, non-disclosing); administrators see the text unchanged (SC-005).

func ServerLogFilename added in v0.38.0

func ServerLogFilename(serverName string) string

ServerLogFilename is the exported accessor for the per-server log filename. Read sites outside this package (the REST/daemon log reader in internal/server and the no-daemon CLI file reader in cmd/mcpproxy) MUST derive the path through this helper so reads resolve to the same sanitized flat file the writers create for namespace/name registry servers (MCP-1111). Do not re-derive "server-%s.log" by hand at a call site.

func SetupCommandLogger

func SetupCommandLogger(serverCommand bool, logLevel string, logToFile bool, logDir string) (*zap.Logger, error)

SetupCommandLogger creates a logger for console commands with appropriate default levels serverCommand: if true, uses INFO level by default; if false, uses WARN level by default

func SetupLogger

func SetupLogger(config *config.LogConfig) (*zap.Logger, error)

SetupLogger creates a logger with file and console outputs based on configuration

Types

type LogDirInfo

type LogDirInfo struct {
	Path        string `json:"path"`
	OS          string `json:"os"`
	Description string `json:"description"`
	Standard    string `json:"standard"`
}

LogDirInfo returns information about the log directory for different OS

func GetLogDirInfo

func GetLogDirInfo() (*LogDirInfo, error)

GetLogDirInfo returns detailed information about the log directory

type LoggerInfo

type LoggerInfo struct {
	LogDir        string    `json:"log_dir"`
	LogFile       string    `json:"log_file"`
	Level         string    `json:"level"`
	EnableFile    bool      `json:"enable_file"`
	EnableConsole bool      `json:"enable_console"`
	MaxSize       int       `json:"max_size"`
	MaxBackups    int       `json:"max_backups"`
	MaxAge        int       `json:"max_age"`
	Compress      bool      `json:"compress"`
	JSONFormat    bool      `json:"json_format"`
	CreatedAt     time.Time `json:"created_at"`
}

LoggerInfo represents information about the logger setup

func GetLoggerInfo

func GetLoggerInfo(config *config.LogConfig) (*LoggerInfo, error)

GetLoggerInfo returns information about the current logger configuration

type SecretSanitizer

type SecretSanitizer struct {
	zapcore.Core
	// contains filtered or unexported fields
}

SecretSanitizer wraps a zapcore.Core to sanitize sensitive values from logs

func NewSecretSanitizer

func NewSecretSanitizer(core zapcore.Core) *SecretSanitizer

NewSecretSanitizer creates a new sanitizing core that wraps the provided core

func (*SecretSanitizer) Check

func (s *SecretSanitizer) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry

Check delegates to the wrapped core

func (*SecretSanitizer) RegisterResolvedSecret

func (s *SecretSanitizer) RegisterResolvedSecret(value string)

RegisterResolvedSecret registers a secret value that was resolved from keyring/env so it can be masked in logs

func (*SecretSanitizer) UnregisterResolvedSecret

func (s *SecretSanitizer) UnregisterResolvedSecret(value string)

UnregisterResolvedSecret removes a secret from the mask cache

func (*SecretSanitizer) With

func (s *SecretSanitizer) With(fields []zapcore.Field) zapcore.Core

With creates a sanitizing child core

func (*SecretSanitizer) Write

func (s *SecretSanitizer) Write(entry zapcore.Entry, fields []zapcore.Field) error

Write sanitizes the entry before writing

Jump to

Keyboard shortcuts

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