Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRequestID ¶
GetRequestID retrieves the request ID from context
Types ¶
type Config ¶
type Config struct {
// Logger is the logger implementation to use
Logger Logger
// Level determines the logging verbosity
Level LogLevel
// Format defines the output format (text or JSON)
Format OutputFormat
// RequestIDGenerator creates unique request identifiers
RequestIDGenerator func() string
// RequestIDHeader is the header name for propagating request IDs
RequestIDHeader string
// SensitiveHeaders are headers that should be redacted
SensitiveHeaders []string
// SkipPaths are URL paths that should not be logged
SkipPaths []string
// SensitiveFields are JSON fields that should be redacted in bodies
SensitiveFields []string
// EnableSampling enables log sampling to reduce volume
EnableSampling bool
// SampleRate defines the log sampling rate (1.0 = 100%)
SampleRate float64
// PropagateRequestID controls whether to propagate request ID
PropagateRequestID bool
}
Config holds the configuration for the logger middleware
type ContextKey ¶
type ContextKey string
ContextKey type for context value storage
const ( // RequestIDKey is the context key for storing request IDs RequestIDKey ContextKey = "request_id" // MaxBodyLogSize limits the body size in logs MaxBodyLogSize = 10 * 1024 // 10KB )
type Logger ¶
type Logger interface {
Log(ctx context.Context, level LogLevel, msg string, fields map[string]interface{})
}
Logger interface allows for integration with any logging library
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements HTTP client logging
func WithLevel ¶
func WithLevel(level LogLevel) *Middleware
WithLevel returns a middleware with the specified log level
func (*Middleware) Handle ¶
func (m *Middleware) Handle(next middleware.Handler) middleware.Handler
Handle implements the middleware.Handler interface
type OutputFormat ¶
type OutputFormat int
OutputFormat defines how logs are formatted
const ( // FormatText outputs logs in human-readable text format FormatText OutputFormat = iota // FormatJSON outputs logs in JSON format FormatJSON )
type StandardLogger ¶
type StandardLogger struct {
Level LogLevel
Format OutputFormat
}
StandardLogger is a simple logger that writes to stdout
Click to show internal directories.
Click to hide internal directories.