authenticationslog

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package authenticationslog adapts authentication instrumentation to log/slog.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instrumenter

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

Instrumenter emits one bounded structured log record per attempt.

func New

func New(logger *slog.Logger) (*Instrumenter, error)

New creates a structured authentication log instrumenter.

Example
package main

import (
	"context"
	"log/slog"
	"os"
	"time"

	authentication "github.com/faustbrian/go-authentication"
	authlog "github.com/faustbrian/go-authentication/adapters/slog"
)

func main() {
	handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
		ReplaceAttr: func(_ []string, attribute slog.Attr) slog.Attr {
			if attribute.Key == slog.TimeKey {
				return slog.Attr{}
			}
			return attribute
		},
	})
	instrumenter, _ := authlog.New(slog.New(handler))
	_, finish := instrumenter.Begin(context.Background(), authentication.CredentialBearer)
	finish(authentication.Event{Outcome: authentication.OutcomeAuthenticated, Duration: time.Millisecond})
}
Output:
{"level":"INFO","msg":"authentication completed","credential_kind":"bearer","outcome":"authenticated","failure_kind":"","duration_ms":1}

func (*Instrumenter) Begin

Begin starts one bounded authentication observation.

func (*Instrumenter) Start deprecated

Start implements the legacy authentication.Instrumenter contract.

Deprecated: use Begin. It matches the preferred observation vocabulary. Migrate callers by replacing Start with Begin. Start remains supported throughout v1; its earliest removal is v2.0.0.

Jump to

Keyboard shortcuts

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