Documentation
¶
Overview ¶
Package logging provides structured JSON-line logging with correlation and tenant identifiers carried through context. It is intended for the ChronosOS control plane: the HTTP middleware stamps each request with a correlation id and execution code logs through the same context so all lines for one request can be joined by correlation_id.
Index ¶
- Constants
- func CorrelationIDFromContext(ctx context.Context) string
- func Middleware(logger *Logger) func(http.Handler) http.Handler
- func NewCorrelationID() string
- func TenantFromContext(ctx context.Context) string
- func WithCorrelationID(ctx context.Context, id string) context.Context
- func WithTenant(ctx context.Context, tenant string) context.Context
- type Level
- type Logger
- func (l *Logger) Debug(ctx context.Context, msg string, fields ...any)
- func (l *Logger) Error(ctx context.Context, msg string, fields ...any)
- func (l *Logger) Info(ctx context.Context, msg string, fields ...any)
- func (l *Logger) Log(ctx context.Context, lvl Level, msg string, fields ...any)
- func (l *Logger) Warn(ctx context.Context, msg string, fields ...any)
- type Option
Constants ¶
const ( HeaderCorrelationID = "X-Correlation-ID" HeaderRequestID = "X-Request-ID" HeaderTenant = "X-Tenant-ID" )
Header names used to propagate correlation and tenant identifiers across service boundaries.
Variables ¶
This section is empty.
Functions ¶
func CorrelationIDFromContext ¶
CorrelationIDFromContext returns the correlation id, or "" if none is set.
func Middleware ¶
Middleware returns an http middleware that ensures every request carries a correlation id (reused from the X-Correlation-ID / X-Request-ID header when present, otherwise generated), stamps it on the request context and the response header, propagates any tenant header into context, and logs the completed request as a structured line.
The integrator can attach this to the ChronosOS server; downstream handlers and execution code then log through the same context via CorrelationIDFromContext / logger methods so all lines for a request share a correlation_id.
func NewCorrelationID ¶
func NewCorrelationID() string
NewCorrelationID generates a random hex correlation id.
func TenantFromContext ¶
TenantFromContext returns the tenant id, or "" if none is set.
func WithCorrelationID ¶
WithCorrelationID returns a context carrying the given correlation id.
func WithTenant ¶
WithTenant returns a context carrying the given tenant id. It delegates to engine/hooks so the tenant set by the HTTP middleware and the tenant read by the metrics PrometheusHook share one context key (single source of truth for per-tenant attribution across the os and engine layers).
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger emits structured JSON log lines to an io.Writer. It is safe for concurrent use.