authlog

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package authlog 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"
	"github.com/faustbrian/go-authentication/authlog"
)

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.Start(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) Start

Start implements authentication.Instrumenter.

Jump to

Keyboard shortcuts

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