logging

package
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 10 Imported by: 0

README

GWC | Logging Library

GoWebComponents (GWC)

High-Level Overview

The logging library provides structured logging surfaces and adapters used by the GWC runtime and tools.

Telemetry Redaction

Use ConfigureTelemetryRedaction to install one process-wide telemetry policy before emitting logs, panic reports, or devtools exports. Field names are matched case-insensitively after punctuation normalization, nested JSON-like values are walked recursively, and redactor failures fail closed by dropping the affected field. With no configured policy, telemetry is emitted unchanged.

Public APIs

github.com/monstercameron/GoWebComponents/logging (package logging)
  • Functions: AttachBrowserConsole, Debug, Error, Info, Log, New, Scope, Warn
  • Types: BrowserConsoleOptions, Fields, Logger
  • Variables: none
  • Constants: none

Subfiles And Purpose

  • backend_native.go - Native (non-WASM) implementation for backend
  • backend_wasm.go - WebAssembly-specific implementation for backend
  • browser_console_stub.go - Core implementation for browser_console_stub
  • browser_console_wasm.go - WebAssembly-specific implementation for browser_console
  • doc.go - Package-level Go documentation
  • logging.go - Core implementation for logging
  • logging_additional_test.go - Tests for logging_additional behavior
  • logging_test.go - Tests for logging behavior
  • redaction.go - Core implementation for redaction
  • redaction_test.go - Tests for redaction behavior

File Map

logging/
|-- backend_native.go
|-- backend_wasm.go
|-- browser_console_stub.go
|-- browser_console_wasm.go
|-- doc.go
|-- logging.go
|-- logging_additional_test.go
|-- logging_test.go
|-- redaction.go
\-- redaction_test.go

Documentation

Overview

Package logging provides a small public structured logging surface for GoWebComponents applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachBrowserConsole

func AttachBrowserConsole(parseConsoleOptions BrowserConsoleOptions) func()

AttachBrowserConsole is a no-op on non-browser targets.

func ConfigureTelemetryRedaction

func ConfigureTelemetryRedaction(parsePolicy RedactionPolicy)

ConfigureTelemetryRedaction installs the current process-wide telemetry redaction policy. Passing the zero value disables policy-based redaction.

func GetCorrelationID

func GetCorrelationID(parseCtx context.Context) string

GetCorrelationID returns the correlation ID stored by StoreCorrelationID.

func Log

func Log(parseLogLevel, parseLogScope, parseLogMessage string, parseLogArgs ...any)

Log writes a structured entry to the configured browser console or fallback output.

func LogContext

func LogContext(parseLogContext context.Context, parseLogLevel, parseLogScope, parseLogMessage string, parseLogArgs ...any)

LogContext writes a structured entry while resolving context-backed correlation and trace metadata.

func RedactStringMap

func RedactStringMap(parsePath string, parseValues map[string]string) map[string]string

RedactStringMap applies telemetry redaction to a string map and drops fields whose redactor fails.

func RedactTelemetryField

func RedactTelemetryField(parsePath string, parseField string, parseValue any) (any, bool)

RedactTelemetryField applies the active redaction policy to one field. The boolean return is false when the field must be dropped.

func RedactTelemetryValue

func RedactTelemetryValue(parsePath string, parseValue any) any

RedactTelemetryValue recursively redacts JSON-like telemetry values.

func StoreCorrelationID

func StoreCorrelationID(parseCtx context.Context, parseCorrelationID string) context.Context

StoreCorrelationID stores one correlation ID in ctx for later log enrichment.

func StoreTraceContext

func StoreTraceContext(parseCtx context.Context, parseTraceContext TraceContext) context.Context

StoreTraceContext stores one trace context in ctx for later log enrichment.

Types

type BrowserConsoleOptions

type BrowserConsoleOptions struct {
	Scope                  string
	LogClicks              bool
	LogChanges             bool
	LogSubmits             bool
	LogWindowErrors        bool
	LogNavigation          bool
	LogMount               bool
	LogDocumentReady       bool
	LogUnhandledRejections bool
	LogVisibility          bool
	LogResize              bool
	LogBeforeUnload        bool
}

BrowserConsoleOptions configures browser event logging on js/wasm builds.

type Fields

type Fields = map[string]any

Fields is the structured payload attached to a log entry.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger writes structured entries under a stable scope.

func New

func New(parseLogScope string) Logger

New returns a scoped logger for application code.

func NewContext

func NewContext(parseLogContext context.Context, parseLogScope string) Logger

NewContext returns a scoped logger that resolves correlation and trace metadata from context.

func (Logger) Debug

func (parseScopedLogger Logger) Debug(parseLogMessage string, parseLogArgs ...any)

Debug writes a debug-level entry.

func (Logger) Error

func (parseScopedLogger Logger) Error(parseLogMessage string, parseLogArgs ...any)

Error writes an error entry.

func (Logger) Info

func (parseScopedLogger Logger) Info(parseLogMessage string, parseLogArgs ...any)

Info writes an info-level entry.

func (Logger) Log

func (parseScopedLogger Logger) Log(parseLogLevel, parseLogMessage string, parseLogArgs ...any)

Log writes a structured entry using the provided level. Any fields attached via With are merged first (so per-call fields override them on a key collision).

func (Logger) Scope

func (parseScopedLogger Logger) Scope() string

Scope returns the logger scope.

func (Logger) Warn

func (parseScopedLogger Logger) Warn(parseLogMessage string, parseLogArgs ...any)

Warn writes a warning entry.

func (Logger) With

func (parseScopedLogger Logger) With(parseLogArgs ...any) Logger

With returns a copy of the logger that attaches the given fields to every subsequent entry, so a component name, request id, or handler need not be repeated on each call. Accepts the same forms as the Log methods (key/value pairs, a Fields map, or slog.Attr). Per-call fields override With fields on a key collision. Mirrors slog.Logger.With.

func (Logger) WithContext

func (parseScopedLogger Logger) WithContext(parseLogContext context.Context) Logger

WithContext returns one scoped logger that resolves correlation and trace metadata from context.

type RedactionContext

type RedactionContext = telemetryredaction.Context

RedactionContext describes one telemetry field being filtered.

type RedactionPolicy

type RedactionPolicy = telemetryredaction.Policy

RedactionPolicy configures opt-in telemetry redaction for logs, panic reports, and devtools exports. Field names are matched case-insensitively against the final path segment. When Redact returns an error the field is dropped to fail closed.

func CurrentTelemetryRedaction

func CurrentTelemetryRedaction() RedactionPolicy

CurrentTelemetryRedaction returns a copy of the active redaction policy.

type TraceContext

type TraceContext struct {
	TraceID      string
	ParentSpanID string
	SpanID       string
	Flags        string
	TraceState   string
}

TraceContext holds W3C trace-context identifiers for one logging scope.

func GetTraceContext

func GetTraceContext(parseCtx context.Context) (TraceContext, bool)

GetTraceContext returns the trace context stored by StoreTraceContext.

func (TraceContext) IsValid

func (parseTraceContext TraceContext) IsValid() bool

IsValid reports whether the trace context carries one usable 128-bit trace ID.

func (TraceContext) Traceparent

func (parseTraceContext TraceContext) Traceparent() string

Traceparent formats the trace context as one W3C traceparent header value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL