log

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package log provides secure telemetry logging with strict security controls.

SECURITY MODEL:

This package implements strict security controls for telemetry logging to prevent PII and sensitive information from being sent to external telemetry services.

REQUIREMENTS:

  • Messages MUST be constant templates only - no dynamic parameter replacement
  • Stack traces MUST be redacted to show only Datadog, runtime, and known 3rd party frames
  • Errors MUST use SafeError type with message redaction
  • slog.Any() only allowed with LogValuer implementations

BENEFITS:

  • Constant messages enable deduplication to reduce redundant log transmission

SECURE USAGE PATTERNS:

// ✅ Correct - constant message with structured data
telemetrylog.Error("operation failed", slog.String("operation", "startup"))
telemetrylog.Error("validation error", slog.Any("error", SafeError(err)))
telemetrylog.Error("operation failed", slog.Any("error", SafeError(err)), WithStacktrace())

// ❌ Forbidden - dynamic messages
telemetrylog.Error(err.Error()) // Raw error message
telemetrylog.Error("failed: " + details) // String concatenation
telemetrylog.Error(fmt.Sprintf("error: %s", err)) // Format strings

// ❌ Forbidden - raw error exposure
telemetrylog.Error("failed", slog.Any("error", err)) // Raw error object
telemetrylog.Error("failed", slog.String("err", err.Error())) // Raw error message

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(message string, attrs ...slog.Attr)

func Error

func Error(message string, attrs ...slog.Attr)

func SetDefaultLogger added in v2.4.0

func SetDefaultLogger(logger *Logger)

func Warn

func Warn(message string, attrs ...slog.Attr)

Types

type Logger added in v2.4.0

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

func With added in v2.4.0

func With(opts ...telemetry.LogOption) *Logger

func (*Logger) Debug added in v2.4.0

func (l *Logger) Debug(message string, attrs ...slog.Attr)

func (*Logger) Error added in v2.4.0

func (l *Logger) Error(message string, attrs ...slog.Attr)

func (*Logger) Warn added in v2.4.0

func (l *Logger) Warn(message string, attrs ...slog.Attr)

func (*Logger) With added in v2.4.0

func (l *Logger) With(opts ...telemetry.LogOption) *Logger

type SafeError added in v2.4.0

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

SafeError represents a sanitized error for secure telemetry logging. It only exposes the error type, never the error message, to prevent PII leakage.

func NewSafeError added in v2.4.0

func NewSafeError(err error) SafeError

NewSafeError creates a SafeError from a regular error

func (SafeError) LogValue added in v2.4.0

func (e SafeError) LogValue() slog.Value

LogValue implements slog.LogValuer to provide secure logging representation

type SafeSlice added in v2.4.0

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

SafeSlice provides secure logging for slice/array types

func NewSafeSlice added in v2.4.0

func NewSafeSlice[T any](items []T) SafeSlice

NewSafeSlice creates a SafeSlice from any slice, converting items to strings

func NewSafeSliceWithLimit added in v2.4.0

func NewSafeSliceWithLimit[T any](items []T, maxItems int) SafeSlice

NewSafeSliceWithLimit creates a SafeSlice with custom item limit

func (SafeSlice) LogValue added in v2.4.0

func (s SafeSlice) LogValue() slog.Value

LogValue implements slog.LogValuer for secure slice logging

Jump to

Keyboard shortcuts

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