Documentation
¶
Index ¶
- type EventType
- type LogEntry
- type Logger
- type PrometheusLogger
- func (p *PrometheusLogger) GetEnforceDuration() *prometheus.HistogramVec
- func (p *PrometheusLogger) GetEnforceTotal() *prometheus.CounterVec
- func (p *PrometheusLogger) GetPolicyOpsDuration() *prometheus.HistogramVec
- func (p *PrometheusLogger) GetPolicyOpsTotal() *prometheus.CounterVec
- func (p *PrometheusLogger) GetPolicyRulesCount() *prometheus.GaugeVec
- func (p *PrometheusLogger) OnAfterEvent(entry *LogEntry) error
- func (p *PrometheusLogger) OnBeforeEvent(entry *LogEntry) error
- func (p *PrometheusLogger) SetEventTypes(eventTypes []EventType) error
- func (p *PrometheusLogger) SetLogCallback(callback func(entry *LogEntry) error) error
- func (p *PrometheusLogger) Unregister()
- func (p *PrometheusLogger) UnregisterFrom(registry *prometheus.Registry) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventType ¶
type EventType string
EventType represents the type of logging event. These types are defined to match the casbin/v2/log package interface.
type LogEntry ¶
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. This type is defined to match the casbin/v2/log package interface.
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. This interface is defined to match the casbin/v2/log package interface.
type PrometheusLogger ¶
type PrometheusLogger struct {
// contains filtered or unexported fields
}
PrometheusLogger is a logger that exports metrics to Prometheus.
func NewPrometheusLogger ¶
func NewPrometheusLogger() *PrometheusLogger
NewPrometheusLogger creates a new PrometheusLogger with default metrics.
func NewPrometheusLoggerWithRegistry ¶
func NewPrometheusLoggerWithRegistry(registry *prometheus.Registry) *PrometheusLogger
NewPrometheusLoggerWithRegistry creates a new PrometheusLogger with a custom registry.
func (*PrometheusLogger) GetEnforceDuration ¶
func (p *PrometheusLogger) GetEnforceDuration() *prometheus.HistogramVec
GetEnforceDuration returns the enforce duration histogram metric.
func (*PrometheusLogger) GetEnforceTotal ¶
func (p *PrometheusLogger) GetEnforceTotal() *prometheus.CounterVec
GetEnforceTotal returns the enforce total counter metric.
func (*PrometheusLogger) GetPolicyOpsDuration ¶
func (p *PrometheusLogger) GetPolicyOpsDuration() *prometheus.HistogramVec
GetPolicyOpsDuration returns the policy operations duration histogram metric.
func (*PrometheusLogger) GetPolicyOpsTotal ¶
func (p *PrometheusLogger) GetPolicyOpsTotal() *prometheus.CounterVec
GetPolicyOpsTotal returns the policy operations total counter metric.
func (*PrometheusLogger) GetPolicyRulesCount ¶
func (p *PrometheusLogger) GetPolicyRulesCount() *prometheus.GaugeVec
GetPolicyRulesCount returns the policy rules count gauge metric.
func (*PrometheusLogger) OnAfterEvent ¶
func (p *PrometheusLogger) OnAfterEvent(entry *LogEntry) error
OnAfterEvent is called after an event completes and records metrics.
func (*PrometheusLogger) OnBeforeEvent ¶
func (p *PrometheusLogger) OnBeforeEvent(entry *LogEntry) error
OnBeforeEvent is called before an event occurs.
func (*PrometheusLogger) SetEventTypes ¶
func (p *PrometheusLogger) SetEventTypes(eventTypes []EventType) error
SetEventTypes configures which event types should be logged.
func (*PrometheusLogger) SetLogCallback ¶
func (p *PrometheusLogger) SetLogCallback(callback func(entry *LogEntry) error) error
SetLogCallback sets a custom callback function for log entries.
func (*PrometheusLogger) Unregister ¶
func (p *PrometheusLogger) Unregister()
Unregister unregisters all metrics from the default Prometheus registry. This is useful for testing or when you need to recreate the logger.
func (*PrometheusLogger) UnregisterFrom ¶
func (p *PrometheusLogger) UnregisterFrom(registry *prometheus.Registry) bool
UnregisterFrom unregisters all metrics from a specific Prometheus registry.
