Documentation
¶
Overview ¶
Package logging provides Spice-native, instance-owned structured logging.
Index ¶
- Constants
- func NewJSONHandler(writer io.Writer, options HandlerOptions) (slog.Handler, error)
- func NewTextHandler(writer io.Writer, options HandlerOptions) (slog.Handler, error)
- type Configuration
- type Controller
- type Correlation
- type ErrorDetails
- type Field
- func Bool(key string, value bool) Field
- func Duration(key string, value time.Duration) Field
- func ErrorFields(err error) []Field
- func Float64(key string, value float64) Field
- func Int64(key string, value int64) Field
- func String(key, value string) Field
- func Time(key string, value time.Time) Field
- func Uint64(key string, value uint64) Field
- type Format
- type HandlerOptions
- type Level
- type LevelRule
- type LevelSnapshot
- type Logger
- func (logger *Logger) Controller() *Controller
- func (logger *Logger) Debug(ctx context.Context, event, message string, fields ...Field) error
- func (logger *Logger) Emit(ctx context.Context, record Record) error
- func (logger *Logger) Error(ctx context.Context, event, message string, fields ...Field) error
- func (logger *Logger) Info(ctx context.Context, event, message string, fields ...Field) error
- func (logger *Logger) Slog() *slog.Logger
- func (logger *Logger) Stats() Stats
- func (logger *Logger) Trace(ctx context.Context, event, message string, fields ...Field) error
- func (logger *Logger) Warn(ctx context.Context, event, message string, fields ...Field) error
- func (logger *Logger) WithScope(scope Scope) (*Logger, error)
- type Options
- type Record
- type SafeError
- type Scope
- type ScopeLevel
- type Stats
Constants ¶
const ( // FormatJSON selects the canonical spice.log/v1 JSON encoding. FormatJSON Format = "json" // FormatText selects stable developer-oriented key-value text. FormatText Format = "text" // JSON is the canonical production format. JSON = FormatJSON // Text is the developer-oriented text format. Text = FormatText )
const ( // LevelTrace enables the most detailed diagnostic records. LevelTrace Level = -8 // LevelDebug enables developer diagnostic records. LevelDebug Level = -4 // LevelInfo enables ordinary operational records. LevelInfo Level = 0 // LevelWarn enables degraded or rejected operation records. LevelWarn Level = 4 // LevelError enables failed operation records. LevelError Level = 8 // LevelOff disables every record in a configured scope. LevelOff Level = 127 // Trace is the canonical trace severity. Trace = LevelTrace // Debug is the canonical debug severity. Debug = LevelDebug // Info is the canonical informational severity. Info = LevelInfo // Warn is the canonical warning severity. Warn = LevelWarn // Error is the canonical error severity. Error = LevelError // Off disables every record in a configured scope. Off = LevelOff )
Variables ¶
This section is empty.
Functions ¶
func NewJSONHandler ¶
NewJSONHandler constructs a canonical spice.log/v1 JSON slog handler.
func NewTextHandler ¶
NewTextHandler constructs a stable developer-oriented text slog handler.
Types ¶
type Configuration ¶
Configuration is resolved before one logger is constructed.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller owns the mutable level policy for one logger. It is safe for concurrent use and never changes process-global state.
func (*Controller) Reset ¶
func (controller *Controller) Reset(scopeID string) error
Reset removes one runtime override and restores its startup policy.
func (*Controller) Set ¶
func (controller *Controller) Set(scopeID string, level Level) error
Set installs a runtime override for root or one registered exact scope.
func (*Controller) Snapshot ¶
func (controller *Controller) Snapshot() LevelSnapshot
Snapshot returns root followed by exact scopes in lexical ID order.
type Correlation ¶
Correlation carries optional W3C-compatible trace identity without owning a tracing SDK or extracting process-global context.
type ErrorDetails ¶
ErrorDetails is explicitly reviewed, bounded information safe for logs.
func ClassifyError ¶
func ClassifyError(err error) ErrorDetails
ClassifyError converts an error into safe fixed details.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is one typed attribute in a safe Spice record. Its representation is opaque so arbitrary values cannot bypass record validation.
func ErrorFields ¶
ErrorFields returns bounded fields for automatic observers.
type HandlerOptions ¶
type HandlerOptions struct{ AddSource bool }
HandlerOptions configure built-in handlers.
type Level ¶
type Level int8
Level is the severity of one structured record.
func ParseLevel ¶
ParseLevel decodes a case-insensitive canonical level name.
func (Level) MarshalJSON ¶
MarshalJSON emits the canonical name used by management responses.
type LevelSnapshot ¶
type LevelSnapshot struct {
Scopes []ScopeLevel `json:"scopes"`
}
LevelSnapshot is a deterministic snapshot of root and registered scopes.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger emits through one standard slog.Handler without mutating globals.
func (*Logger) Controller ¶
func (logger *Logger) Controller() *Controller
Controller returns this logger's exact-scope level controller.
func (*Logger) Emit ¶
Emit validates and writes one record. Handler errors are returned and counted; no secondary log is emitted.
func (*Logger) Slog ¶
Slog returns an instance-owned compatibility adapter. Generic slog values are outside the safe Field contract and remain the caller's responsibility.
type Options ¶
type Options struct {
Application string
Configuration Configuration
Writer io.Writer
Handler slog.Handler
Scopes []Scope
}
Options construct one application-owned logger. Writer and Handler are mutually exclusive; omitting both creates an explicit discard logger.
type Record ¶
type Record struct {
Timestamp time.Time
Level Level
Event string
Message string
Scope Scope
Correlation Correlation
Fields []Field
}
Record is one validated Spice-native structured event.
type SafeError ¶
type SafeError interface {
error
SafeLogError() ErrorDetails
}
SafeError opts one error into reviewed structured details. Implementations must never return secrets, user content, raw rejected input, or stack traces.
type Scope ¶
Scope is one exact logging ownership boundary. A component always belongs to a module; the zero value is the application root.