Documentation
¶
Index ¶
- func Critical(ctx context.Context, fnName, errorPath, msg string, opts ...Option)
- func Error(ctx context.Context, fnName, errorPath, msg string, opts ...Option)
- func Info(ctx context.Context, fnName string, msg string, opts ...Option)
- func InitConfig(cfg Config)
- func Logger() zerolog.Logger
- func TraceIDFromContext(ctx context.Context) (context.Context, string)
- func Warn(ctx context.Context, fnName, errorPath, msg string, opts ...Option)
- func WithTraceID(ctx context.Context, traceID string) context.Context
- type Config
- type Event
- type Exception
- type Option
- func WithComponent(component string) Option
- func WithDurationMs(ms int64) Option
- func WithEnvironment(env string) Option
- func WithEvent(evName string) Option
- func WithException(err error) Option
- func WithMessageID(id string) Option
- func WithMetadata(metadata map[string]any) Option
- func WithPayloadID(id string) Option
- func WithRetryCount(count int) Option
- func WithServiceVersion(v string) Option
- func WithTopic(topic string) Option
- func WithTrace(traceID, spanID string) Option
- func WithTraceFromContext(ctx context.Context) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Critical ¶
Critical logs a critical event. REQUIRED FIELD: fnName and errorPath must both be provided and non-empty.
func Error ¶
Error logs an error event. REQUIRED FIELD: fnName and errorPath must both be provided and non-empty.
func InitConfig ¶
func InitConfig(cfg Config)
InitConfig initializes global logging configuration. This must be called once during application startup before using the logging package.
func TraceIDFromContext ¶
TraceIDFromContext extracts the trace ID from the context. If none is found, a new one is generated and attached.
Types ¶
type Config ¶
type Config struct {
// Service is the logical service name for this application.
// REQUIRED FIELD: Must be provided and non-empty.
Service string
// Env represents the deployment environment (e.g. "development", "staging", "production").
// CONFIGURABLE
Env string
// ServiceVersion is the deployed version identifier (e.g. semantic version or git SHA).
// CONFIGURABLE
ServiceVersion string
// RedactKeys are case-insensitive field names that should be redacted from metadata/properties.
// Example: ["password", "token", "authorization", "ssn"].
// CONFIGURABLE
RedactKeys []string
// LogDir is the directory where log files will be written.
// Only used when EnableFile is true.
// CONFIGURABLE
LogDir string
// EnableFile writes logs to a file at LogDir/app.log.
// Disabled by default; suitable for containerised deployments where stderr is collected.
EnableFile bool
// ConsoleJSON determines whether console output should be JSON (true)
// or a human-friendly pretty format (false).
// CONFIGURABLE
ConsoleJSON bool
// EnableSeq toggles sending logs to Seq over HTTP.
// Can also be enabled by setting SEQ_ENABLE=true in the environment.
// CONFIGURABLE
EnableSeq bool
// SeqURL is the base URL of the Seq server (e.g. "http://localhost:5341").
// Can also be set via the SEQ_URL environment variable.
// CONFIGURABLE
SeqURL string
// SeqAPIKey is an optional API key for authenticating with Seq.
// Can also be set via the SEQ_API_KEY environment variable.
// CONFIGURABLE
SeqAPIKey string
// TimeFormat is the layout used for timestamps when pretty-printing.
// CONFIGURABLE
TimeFormat string
}
Config holds all logging configuration. CONFIGURABLE: All fields in this struct are intended to be set from application configuration.
func ConfigOrDefault ¶
func ConfigOrDefault() Config
ConfigOrDefault returns the current globalConfig. It panics if InitConfig has not been called.
type Event ¶
type Event struct {
// Required / baseline fields
Service string `json:"service"`
ServiceVersion string `json:"service_version,omitempty"`
Environment string `json:"environment,omitempty"`
Component string `json:"component,omitempty"`
TraceID string `json:"trace_id"`
SpanID string `json:"span_id,omitempty"`
// event is the canonical field name for business/saga event names.
Event string `json:"event,omitempty"`
// Location/context fields
Function string `json:"function,omitempty"`
ErrorPath string `json:"error_path,omitempty"`
Topic string `json:"topic,omitempty"`
MessageID string `json:"message_id,omitempty"`
PayloadID string `json:"payload_id,omitempty"`
RetryCount int `json:"retry_count,omitempty"`
DurationMs int64 `json:"duration_ms,omitempty"`
// Additional structured context
Metadata map[string]any `json:"metadata,omitempty"`
Exception *Exception `json:"exception,omitempty"`
}
Event represents a structured log event with required and optional fields.
Note: This struct is primarily used as an internal carrier for field values. The logger writes fields using zerolog; not all struct fields are serialized directly.
type Exception ¶
type Exception struct {
Type string `json:"type,omitempty"`
Message string `json:"message,omitempty"`
Stack string `json:"stack,omitempty"`
}
Exception represents a structured error payload for logs.
type Option ¶
type Option func(*Event)
Option allows adding optional metadata to an Event. EXTENSION POINT: Add more option helpers for additional fields.
func WithComponent ¶
WithComponent sets the architectural component (e.g. "Orchestrator", "Participant").
func WithDurationMs ¶
WithDurationMs records the operation duration in milliseconds.
func WithEnvironment ¶
WithEnvironment sets the deployment environment, overriding the config default.
func WithException ¶
WithException populates the structured exception field. If err is nil, this option does nothing.
func WithMessageID ¶
WithMessageID records the message broker message ID.
func WithMetadata ¶
WithMetadata attaches arbitrary business-context key/value pairs; sensitive keys are redacted.
func WithPayloadID ¶
WithPayloadID records the payload identifier.
func WithRetryCount ¶
WithRetryCount records the number of retry attempts made.
func WithServiceVersion ¶
WithServiceVersion sets the service version, overriding the config default.
func WithTraceFromContext ¶
WithTraceFromContext is a no-op unless built with -tags=otel.