{"modulePath":"github.com/openshift-hyperfleet/hyperfleet-api","version":"v0.4.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package logger\n\n## Constants\n\n```go\nconst (\n\tReqIDKey           contextKey = \"request_id\"\n\tTraceIDCtxKey      contextKey = \"trace_id\"\n\tSpanIDCtxKey       contextKey = \"span_id\"\n\tClusterIDCtxKey    contextKey = \"cluster_id\"\n\tResourceTypeCtxKey contextKey = \"resource_type\"\n\tResourceIDCtxKey   contextKey = \"resource_id\"\n)\n```\nContext keys for storing correlation fields\n\n```go\nconst (\n\tFieldBindAddress = \"bind_address\"\n\tFieldEnvironment = \"environment\"\n\tFieldLogLevel    = \"level\"\n\tFieldLogFormat   = \"format\"\n\tFieldLogOutput   = \"output\"\n)\n```\nServer/Config related fields\n\n```go\nconst (\n\tFieldMigrationID = \"migration_id\"\n\t// FieldConnectionString - WARNING: Always sanitize connection strings before logging\n\t// to prevent exposing passwords. Never log raw connection strings.\n\tFieldConnectionString = \"connection_string\"\n\tFieldTable            = \"table\"\n\tFieldChannel          = \"channel\"\n\tFieldLockID           = \"lock_id\"\n\tFieldLockType         = \"lock_type\"\n\tFieldLockDurationMs   = \"lock_duration_ms\"\n)\n```\nDatabase related fields\n\n```go\nconst (\n\tFieldOTelEnabled              = \"otel_enabled\"\n\tFieldSamplingRate             = \"sampling_rate\"\n\tFieldExporterEndpoint         = \"exporter_endpoint\"\n\tFieldHyperfleetTracingEnabled = \"hyperfleet_tracing_enabled\"\n\tFieldServiceName              = \"service_name\"\n\tFieldProtocol                 = \"protocol\"\n\tFieldSampler                  = \"sampler\"\n\tFieldServiceVersion           = \"service_version\"\n)\n```\nOpenTelemetry related fields\n\n```go\nconst (\n\tFieldAdapter   = \"adapter\"\n\tFieldErrorCode = \"error_code\"\n\tFieldFlag      = \"flag\"\n\tFieldData      = \"data\"\n)\n```\nGeneric fields\n\n```go\nconst (\n\tFieldHTTPMethod     = \"method\"\n\tFieldHTTPPath       = \"path\"\n\tFieldHTTPStatusCode = \"status_code\"\n\tFieldHTTPDuration   = \"duration_ms\"\n\tFieldHTTPUserAgent  = \"user_agent\"\n)\n```\nHTTP field name constants\n\n```go\nconst (\n\tFieldEndpoint = \"endpoint\"\n)\n```\nEndpoint related fields (used in handlers)\n\n```go\nconst (\n\tFieldNodePoolID = \"nodepool_id\"\n)\n```\nResource related fields\n\n```go\nconst (\n\tFieldSchemaPath = \"schema_path\"\n)\n```\nSchema related fields\n\n```go\nconst (\n\tReqIDHeader = \"X-Request-ID\"\n)\n```\nHTTP header names\n\n## Variables\n\n```go\nvar ContextFieldsRegistry = []ContextField{\n\t{GetRequestID, ReqIDKey, \"request_id\"},\n\t{GetTraceID, TraceIDCtxKey, \"trace_id\"},\n\t{GetSpanID, SpanIDCtxKey, \"span_id\"},\n\t{GetClusterID, ClusterIDCtxKey, \"cluster_id\"},\n\t{GetResourceType, ResourceTypeCtxKey, \"resource_type\"},\n\t{GetResourceID, ResourceIDCtxKey, \"resource_id\"},\n}\n```\nContextFieldsRegistry defines all string-type context fields for logging This is the single source of truth for string field management Fields are ordered as per HyperFleet Logging Specification (docs/logging.md:384)\n\n## Functions\n\n```go\nfunc Debug(ctx context.Context, msg string)\n```\nDebug logs at Debug level with context fields only. For temporary fields, use With().\n\n```go\nfunc Error(ctx context.Context, msg string)\n```\nError logs at Error level with context fields only. For temporary fields, use With().\n\n```go\nfunc GetClusterID(ctx context.Context) (string, bool)\n```\nGetClusterID retrieves cluster ID from context\n\n```go\nfunc GetLogger() *slog.Logger\n```\nGetLogger returns the global logger instance\n\n```go\nfunc GetRequestID(ctx context.Context) (string, bool)\n```\nGetRequestID retrieves request ID from context\n\n```go\nfunc GetResourceID(ctx context.Context) (string, bool)\n```\nGetResourceID retrieves resource ID from context\n\n```go\nfunc GetResourceType(ctx context.Context) (string, bool)\n```\nGetResourceType retrieves resource type from context\n\n```go\nfunc GetSpanID(ctx context.Context) (string, bool)\n```\nGetSpanID retrieves span ID from context\n\n```go\nfunc GetTraceID(ctx context.Context) (string, bool)\n```\nGetTraceID retrieves trace ID from context\n\n```go\nfunc HTTPDuration(d time.Duration) slog.Attr\n```\nHTTPDuration returns a slog attribute for HTTP request duration in milliseconds\n\n```go\nfunc HTTPMethod(method string) slog.Attr\n```\nHTTPMethod returns a slog attribute for HTTP method\n\n```go\nfunc HTTPPath(path string) slog.Attr\n```\nHTTPPath returns a slog attribute for HTTP path\n\n```go\nfunc HTTPStatusCode(code int) slog.Attr\n```\nHTTPStatusCode returns a slog attribute for HTTP status code\n\n```go\nfunc HTTPUserAgent(ua string) slog.Attr\n```\nHTTPUserAgent returns a slog attribute for HTTP user agent\n\n```go\nfunc Info(ctx context.Context, msg string)\n```\nInfo logs at Info level with context fields only. For temporary fields, use With().\n\n```go\nfunc InitGlobalLogger(cfg *LogConfig)\n```\nInitGlobalLogger initializes the global logger with the given configuration. This function is idempotent (safe to call multiple times).\n\nConcurrency note: This function uses atomic.Value without sync.Once intentionally. Current call sites are serialized (single-threaded main() and sync.Once in tests). If concurrent initialization occurs, the last Store() wins, which is acceptable. For stricter guarantees in future use cases, callers should wrap this with sync.Once or equivalent synchronization.\n\n```go\nfunc NewHyperFleetHandler(cfg *LogConfig) slog.Handler\n```\nNewHyperFleetHandler creates a HyperFleet logger handler Returns slog.Handler interface to support both HyperFleetHandler (JSON) and HyperFleetTextHandler (Text)\n\n```go\nfunc ParseLogLevel(level string) (slog.Level, error)\n```\nParseLogLevel converts string to slog.Level\n\n```go\nfunc ParseLogOutput(output string) (io.Writer, error)\n```\nParseLogOutput converts string to io.Writer\n\n```go\nfunc ReconfigureGlobalLogger(cfg *LogConfig)\n```\nReconfigureGlobalLogger reconfigures the global logger with new configuration Unlike InitGlobalLogger, this can be called multiple times to update configuration This is useful when environment configuration is loaded after initial logger setup\n\n```go\nfunc RequestIDMiddleware(handler http.Handler) http.Handler\n```\nRequestIDMiddleware Middleware wraps the given HTTP handler so that the details of the request are sent to the log.\n\n```go\nfunc Warn(ctx context.Context, msg string)\n```\nWarn logs at Warn level with context fields only. For temporary fields, use With().\n\n```go\nfunc WithClusterID(ctx context.Context, clusterID string) context.Context\n```\nWithClusterID adds cluster ID to context\n\n```go\nfunc WithRequestID(ctx context.Context) (context.Context, error)\n```\nWithRequestID adds request ID to context If request ID already exists in context, it returns the context unchanged Otherwise, it generates a new UUID v7 and adds it to the context Returns an error if UUID generation fails (extremely unlikely in practice)\n\n```go\nfunc WithResourceID(ctx context.Context, resourceID string) context.Context\n```\nWithResourceID adds resource ID to context\n\n```go\nfunc WithResourceType(ctx context.Context, resourceType string) context.Context\n```\nWithResourceType adds resource type to context\n\n```go\nfunc WithSpanID(ctx context.Context, spanID string) context.Context\n```\nWithSpanID adds span ID to context\n\n```go\nfunc WithTraceID(ctx context.Context, traceID string) context.Context\n```\nWithTraceID adds trace ID to context\n\n## Types\n\n```go\ntype ContextField struct {\n\tGetter func(context.Context) (string, bool)\n\tKey    contextKey\n\tName   string\n}\n```\nContextField defines metadata for a string-type context log field\n\n```go\ntype ContextLogger struct {\n\t// contains filtered or unexported fields\n}\n```\nContextLogger wraps a context with additional temporary key-value pairs for logging.\n\n```go\nfunc With(ctx context.Context, args ...any) *ContextLogger\n```\nWith creates a new ContextLogger with temporary key-value pairs.\n\n```go\nfunc WithError(ctx context.Context, err error) *ContextLogger\n```\nWithError is a convenience function for adding error field to logs.\n\n```go\nfunc (l *ContextLogger) Debug(msg string)\n```\n\n```go\nfunc (l *ContextLogger) Error(msg string)\n```\n\n```go\nfunc (l *ContextLogger) Info(msg string)\n```\n\n```go\nfunc (l *ContextLogger) Warn(msg string)\n```\n\n```go\nfunc (l *ContextLogger) With(args ...any) *ContextLogger\n```\nWith adds additional temporary fields to the logger and can be chained.\n\n```go\nfunc (l *ContextLogger) WithError(err error) *ContextLogger\n```\nWithError adds an error field to the logger and can be chained.\n\n```go\ntype GormLogger struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewGormLogger(logLevel gormlogger.LogLevel, slowThreshold time.Duration) *GormLogger\n```\n\n```go\nfunc (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})\n```\n\n```go\nfunc (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})\n```\n\n```go\nfunc (l *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface\n```\n\n```go\nfunc (l *GormLogger) Trace(\n\tctx context.Context,\n\tbegin time.Time,\n\tfc func() (sql string, rowsAffected int64),\n\terr error,\n)\n```\n\n```go\nfunc (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})\n```\n\n```go\ntype HyperFleetHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nHyperFleetHandler implements slog.Handler interface Adds HyperFleet-specific fields: component, version, hostname, trace\\_id, span\\_id, etc.\n\n```go\nfunc (h *HyperFleetHandler) Enabled(ctx context.Context, level slog.Level) bool\n```\nEnabled implements slog.Handler interface\n\n```go\nfunc (h *HyperFleetHandler) Handle(ctx context.Context, r slog.Record) error\n```\nHandle implements slog.Handler interface\n\n```go\nfunc (h *HyperFleetHandler) WithAttrs(attrs []slog.Attr) slog.Handler\n```\nWithAttrs implements slog.Handler interface\n\n```go\nfunc (h *HyperFleetHandler) WithGroup(name string) slog.Handler\n```\nWithGroup implements slog.Handler interface\n\n```go\ntype HyperFleetTextHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nHyperFleetTextHandler implements the HyperFleet Logging Specification text format: {timestamp} {LEVEL} \\[{component}] \\[{version}] \\[{hostname}] {message} {key=value}...\n\nExample output: 2026-01-09T12:30:45Z INFO \\[hyperfleet-api] \\[v1.2.3] \\[pod-abc] Processing request request\\_id=xyz cluster\\_id=abc123\n\n```go\nfunc NewHyperFleetTextHandler(\n\tw io.Writer, component, version, hostname string, level slog.Level,\n) *HyperFleetTextHandler\n```\nNewHyperFleetTextHandler creates a new text handler conforming to HyperFleet Logging Specification\n\n```go\nfunc (h *HyperFleetTextHandler) Enabled(_ context.Context, level slog.Level) bool\n```\nEnabled reports whether the handler handles records at the given level\n\n```go\nfunc (h *HyperFleetTextHandler) Handle(ctx context.Context, r slog.Record) error\n```\n\n```go\nfunc (h *HyperFleetTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler\n```\n\n```go\nfunc (h *HyperFleetTextHandler) WithGroup(name string) slog.Handler\n```\nWithGroup returns a new handler with a group name\n\n```go\ntype LogConfig struct {\n\tOutput    io.Writer\n\tComponent string\n\tVersion   string\n\tHostname  string\n\tLevel     slog.Level\n\tFormat    LogFormat\n}\n```\nLogConfig holds the configuration for the logger\n\n```go\ntype LogFormat int\n```\nLogFormat enumeration for output format\n\n```go\nconst (\n\t// FormatText outputs logs in human-readable text format\n\tFormatText LogFormat = iota\n\t// FormatJSON outputs logs in JSON format for structured logging\n\tFormatJSON\n)\n```\n\n```go\nfunc ParseLogFormat(format string) (LogFormat, error)\n```\nParseLogFormat converts string to LogFormat\n\n","path":"github.com/openshift-hyperfleet/hyperfleet-api/pkg/logger","name":"logger","synopsis":"","isRedistributable":true}
