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 ¶
func (i *Instrumenter) Start( ctx context.Context, kind authentication.CredentialKind, ) (context.Context, func(authentication.Event))
Start implements authentication.Instrumenter.
Click to show internal directories.
Click to hide internal directories.