log

package
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

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

DefaultLogger is the default implementation of the Logger interface.

func NewDefaultLogger added in v3.7.0

func NewDefaultLogger() *DefaultLogger

NewDefaultLogger creates a new DefaultLogger instance. If no output is set via SetOutput, it defaults to os.Stdout.

func (*DefaultLogger) OnAfterEvent added in v3.7.0

func (l *DefaultLogger) OnAfterEvent(entry *LogEntry) error

OnAfterEvent is called after an event completes. It calculates the duration, logs the entry if active, and calls the user callback if set.

func (*DefaultLogger) OnBeforeEvent added in v3.7.0

func (l *DefaultLogger) OnBeforeEvent(entry *LogEntry) error

OnBeforeEvent is called before an event occurs. It sets the StartTime and determines if the event should be active based on configured event types.

func (*DefaultLogger) SetEventTypes added in v3.7.0

func (l *DefaultLogger) SetEventTypes(eventTypes []EventType) error

SetEventTypes sets the event types that should be logged. Only events matching these types will have IsActive set to true.

func (*DefaultLogger) SetLogCallback added in v3.7.0

func (l *DefaultLogger) SetLogCallback(callback func(entry *LogEntry) error) error

SetLogCallback sets a user-provided callback function. The callback is called at the end of OnAfterEvent.

func (*DefaultLogger) SetOutput added in v3.7.0

func (l *DefaultLogger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger. It can be set to a buffer or any io.Writer.

type EventType added in v3.7.0

type EventType string

EventType represents the type of logging event.

const (
	EventEnforce      EventType = "enforce"
	EventAddPolicy    EventType = "addPolicy"
	EventRemovePolicy EventType = "removePolicy"
	EventLoadPolicy   EventType = "loadPolicy"
	EventSavePolicy   EventType = "savePolicy"
)

Event type constants.

type LogEntry added in v3.7.0

type LogEntry struct {
	IsActive bool
	// EventType is the type of the event being logged.
	EventType EventType

	StartTime time.Time
	EndTime   time.Time
	Duration  time.Duration

	// Enforce parameters.
	// Subject is the user or entity requesting access.
	Subject string
	// Object is the resource being accessed.
	Object string
	// Action is the operation being performed.
	Action string
	// Domain is the domain/tenant for multi-tenant scenarios.
	Domain string
	// Allowed indicates whether the enforcement request was allowed.
	Allowed bool

	// Rules contains the policy rules involved in the operation.
	Rules [][]string
	// RuleCount is the number of rules affected by the operation.
	RuleCount int

	// Error contains any error that occurred during the event.
	Error error
}

LogEntry represents a complete log entry for a Casbin event.

type Logger

type Logger interface {
	SetEventTypes([]EventType) error
	// OnBeforeEvent is called before an event occurs and returns a handle for context.
	OnBeforeEvent(entry *LogEntry) error
	// OnAfterEvent is called after an event completes with the handle and final entry.
	OnAfterEvent(entry *LogEntry) error

	SetLogCallback(func(entry *LogEntry) error) error
}

Logger defines the interface for event-driven logging in Casbin.

Jump to

Keyboard shortcuts

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