logging

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logging provides structured logging for mycelicmemory.

This package wraps Go's log/slog package to provide consistent, structured logging across all mycelicmemory components.

Usage:

import "github.com/MycelicMemory/mycelicmemory/internal/logging"

// Initialize once at startup
logging.Init(logging.Config{
    Level:  "info",
    Format: "json",
    Output: "stderr",
})

// Get a logger for a component
log := logging.GetLogger("mcp")

// Log with context
log.Info("request received", "method", "tools/call", "tool", "store_memory")
log.Error("operation failed", "error", err, "memory_id", id)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, args ...any)

Debug logs at debug level using the default logger

func Error

func Error(msg string, args ...any)

Error logs at error level using the default logger

func Info

func Info(msg string, args ...any)

Info logs at info level using the default logger

func Init

func Init(cfg Config)

Init initializes the global logger with the given configuration. This should be called once at application startup.

func Warn

func Warn(msg string, args ...any)

Warn logs at warn level using the default logger

Types

type Config

type Config struct {
	// Level is the minimum log level: debug, info, warn, error
	Level string
	// Format is the output format: console, json
	Format string
	// Output is the output destination: stderr, stdout, or a file path
	Output string
}

Config holds logging configuration

type Logger

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

Logger wraps slog.Logger with convenience methods

func GetLogger

func GetLogger(component string) *Logger

GetLogger returns a logger for the specified component. The component name is added as an attribute to all log entries.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs at debug level

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs at error level

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs at info level

func (*Logger) LogError

func (l *Logger) LogError(operation string, err error, args ...any)

LogError logs an error with context

func (*Logger) LogOperation

func (l *Logger) LogOperation(operation string, args ...any)

LogOperation logs a successful operation

func (*Logger) LogRequest

func (l *Logger) LogRequest(method string, args ...any)

LogRequest logs an incoming request

func (*Logger) LogResponse

func (l *Logger) LogResponse(method string, duration float64, args ...any)

LogResponse logs an outgoing response

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs at warn level

func (*Logger) With

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

With returns a new Logger with the given attributes added

Jump to

Keyboard shortcuts

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