middlewares

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

fastlog/middlewares

Import path: github.com/InsideGallery/core/fastlog/middlewares

middlewares contains reusable slog middleware for fastlog pipelines.

Main APIs

  • CallerMiddleware adds a caller attribute in file:line form while preserving existing attributes.
  • ErrorFormattingMiddleware converts an error attribute holding an error value into a group with type and message fields.
  • NewGDPRMiddleware() returns a handler middleware that masks exact keys password, email, and phone with *******.

Usage

package example

import (
	"github.com/InsideGallery/core/fastlog"
	"github.com/InsideGallery/core/fastlog/middlewares"
)

func configureLogging() error {
	cfg, err := fastlog.GetConfigFromEnv()
	if err != nil {
		return err
	}

	return fastlog.SetupDefaultLogger(cfg, middlewares.NewGDPRMiddleware())
}

Operational Notes

fastlog.Config wires CallerMiddleware from LOG_CALLER and ErrorFormattingMiddleware from LOG_ERROR_FORMATTING. Custom middleware passed to GetHandler or SetupDefaultLogger runs after those built-in middlewares.

The GDPR middleware masks matching top-level attributes, attributes added through WithAttrs, and nested group attributes when the group name or attribute key is one of the configured PII keys.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerMiddleware

func CallerMiddleware(ctx context.Context, record slog.Record, next func(context.Context, slog.Record) error) error

CallerMiddleware adds source file and line information to log records.

func ErrorFormattingMiddleware

func ErrorFormattingMiddleware(
	ctx context.Context,
	record slog.Record,
	next func(context.Context, slog.Record) error,
) error

ErrorFormattingMiddleware converts error attributes into structured groups with "type" and "message" fields.

func NewGDPRMiddleware

func NewGDPRMiddleware() slogmulti.Middleware

NewGDPRMiddleware returns a slog middleware that masks common PII fields.

Types

This section is empty.

Jump to

Keyboard shortcuts

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