Documentation
¶
Index ¶
- func BatchDecisionIDFromContext(ctx context.Context) (string, bool)
- func DecisionIDFromContext(ctx context.Context) (string, bool)
- func NewContext(parent context.Context, val *RequestContext) context.Context
- func NewSlogHandler(logger Logger) slog.Handler
- func WithBatchDecisionID(parent context.Context, id string) context.Context
- func WithDecisionID(parent context.Context, id string) context.Context
- func WithHTTPRequestContext(parent context.Context, val *HTTPRequestContext) context.Context
- type BufferedLogger
- func (b *BufferedLogger) Close()
- func (b *BufferedLogger) Debug(format string, args ...any)
- func (b *BufferedLogger) Error(format string, args ...any)
- func (b *BufferedLogger) Flush(targetLogger Logger)
- func (b *BufferedLogger) GetLevel() Level
- func (b *BufferedLogger) Info(format string, args ...any)
- func (b *BufferedLogger) SetLevel(level Level)
- func (b *BufferedLogger) Warn(format string, args ...any)
- func (b *BufferedLogger) WithFields(fields map[string]any) Logger
- type HTTPRequestContext
- type Level
- type Logger
- type LoggerWithContext
- type NoOpLogger
- func (*NoOpLogger) Debug(string, ...any)
- func (*NoOpLogger) Error(string, ...any)
- func (l *NoOpLogger) GetLevel() Level
- func (*NoOpLogger) Info(string, ...any)
- func (l *NoOpLogger) SetLevel(level Level)
- func (*NoOpLogger) Warn(string, ...any)
- func (l *NoOpLogger) WithFields(fields map[string]any) Logger
- type RequestContext
- type SlogHandler
- type StandardLogger
- func (l *StandardLogger) Debug(fmt string, a ...any)
- func (l *StandardLogger) Error(fmt string, a ...any)
- func (l *StandardLogger) GetLevel() Level
- func (l *StandardLogger) Info(fmt string, a ...any)
- func (l *StandardLogger) SetFormatter(formatter logrus.Formatter)
- func (l *StandardLogger) SetLevel(level Level)
- func (l *StandardLogger) SetOutput(w io.Writer)
- func (l *StandardLogger) Warn(fmt string, a ...any)
- func (l *StandardLogger) WithFields(fields map[string]any) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchDecisionIDFromContext ¶ added in v1.7.0
func NewContext ¶
func NewContext(parent context.Context, val *RequestContext) context.Context
NewContext returns a copy of parent with an associated RequestContext.
func NewSlogHandler ¶ added in v1.15.0
NewSlogHandler creates an slog.Handler from a Logger
func WithBatchDecisionID ¶ added in v1.7.0
func WithHTTPRequestContext ¶
func WithHTTPRequestContext(parent context.Context, val *HTTPRequestContext) context.Context
Types ¶
type BufferedLogger ¶ added in v1.15.0
type BufferedLogger struct {
// contains filtered or unexported fields
}
BufferedLogger captures log entries in memory until Flush is called, at which point it replays all buffered entries to the target logger. After Flush() is called, the BufferedLogger should not be used anymore.
func NewBufferedLogger ¶ added in v1.15.0
func NewBufferedLogger(maxEntries int) *BufferedLogger
NewBufferedLogger creates a new buffered logger that will buffer up to maxEntries.
func (*BufferedLogger) Close ¶ added in v1.15.0
func (b *BufferedLogger) Close()
Close discards all buffered entries without flushing them. After calling Close, the BufferedLogger should not be used anymore.
func (*BufferedLogger) Debug ¶ added in v1.15.0
func (b *BufferedLogger) Debug(format string, args ...any)
func (*BufferedLogger) Error ¶ added in v1.15.0
func (b *BufferedLogger) Error(format string, args ...any)
func (*BufferedLogger) Flush ¶ added in v1.15.0
func (b *BufferedLogger) Flush(targetLogger Logger)
Flush replays all buffered entries to the target logger. After calling Flush, the BufferedLogger should not be used anymore. The caller should switch to using the target logger directly.
func (*BufferedLogger) GetLevel ¶ added in v1.15.0
func (b *BufferedLogger) GetLevel() Level
GetLevel returns the current log level.
func (*BufferedLogger) Info ¶ added in v1.15.0
func (b *BufferedLogger) Info(format string, args ...any)
func (*BufferedLogger) SetLevel ¶ added in v1.15.0
func (b *BufferedLogger) SetLevel(level Level)
SetLevel sets the log level.
func (*BufferedLogger) Warn ¶ added in v1.15.0
func (b *BufferedLogger) Warn(format string, args ...any)
func (*BufferedLogger) WithFields ¶ added in v1.15.0
func (b *BufferedLogger) WithFields(fields map[string]any) Logger
WithFields returns a new logger with additional fields.
type HTTPRequestContext ¶
func HTTPRequestContextFromContext ¶
func HTTPRequestContextFromContext(ctx context.Context) (*HTTPRequestContext, bool)
type Logger ¶
type Logger interface {
Debug(fmt string, a ...any)
Info(fmt string, a ...any)
Error(fmt string, a ...any)
Warn(fmt string, a ...any)
WithFields(map[string]any) Logger
GetLevel() Level
SetLevel(Level)
}
Logger provides interface for OPA logger implementations
func NewLoggerFromSlogHandler ¶ added in v1.15.0
NewLoggerFromSlogHandler creates a Logger from an slog.Handler
type LoggerWithContext ¶ added in v1.15.1
LoggerWithContext is an optional interface that Logger implementations can implement to support extracting trace information from a context. Use WithContext to call this method on a Logger if it is supported.
type NoOpLogger ¶
type NoOpLogger struct {
// contains filtered or unexported fields
}
NoOpLogger logging implementation that does nothing
func (*NoOpLogger) WithFields ¶
func (l *NoOpLogger) WithFields(fields map[string]any) Logger
WithFields provides additional fields to include in log output. Implemented here primarily to be able to switch between implementations without loss of data.
type RequestContext ¶
type RequestContext struct {
ClientAddr string
ReqID uint64
ReqMethod string
ReqPath string
HTTPRequestContext HTTPRequestContext
}
RequestContext represents the request context used to store data related to the request that could be used on logs.
func FromContext ¶
func FromContext(ctx context.Context) (*RequestContext, bool)
FromContext returns the RequestContext associated with ctx, if any.
func (RequestContext) Fields ¶
func (rctx RequestContext) Fields() logrus.Fields
Fields adapts the RequestContext fields to logrus.Fields.
type SlogHandler ¶ added in v1.15.0
type SlogHandler struct {
// contains filtered or unexported fields
}
SlogHandler adapts a Logger to slog.Handler interface
type StandardLogger ¶
type StandardLogger struct {
// contains filtered or unexported fields
}
StandardLogger is the default OPA logger implementation.
func Get ¶
func Get() *StandardLogger
Get returns the standard logger used throughout OPA.
Deprecated. Do not rely on the global logger.
func (*StandardLogger) Debug ¶
func (l *StandardLogger) Debug(fmt string, a ...any)
Debug logs at debug level
func (*StandardLogger) Error ¶
func (l *StandardLogger) Error(fmt string, a ...any)
Error logs at error level
func (*StandardLogger) GetLevel ¶
func (l *StandardLogger) GetLevel() Level
GetLevel returns the standard logger level.
func (*StandardLogger) Info ¶
func (l *StandardLogger) Info(fmt string, a ...any)
Info logs at info level
func (*StandardLogger) SetFormatter ¶
func (l *StandardLogger) SetFormatter(formatter logrus.Formatter)
SetFormatter sets the underlying logrus formatter.
func (*StandardLogger) SetLevel ¶
func (l *StandardLogger) SetLevel(level Level)
SetLevel sets the standard logger level.
func (*StandardLogger) SetOutput ¶
func (l *StandardLogger) SetOutput(w io.Writer)
SetOutput sets the underlying logrus output.
func (*StandardLogger) Warn ¶
func (l *StandardLogger) Warn(fmt string, a ...any)
Warn logs at warn level
func (*StandardLogger) WithFields ¶
func (l *StandardLogger) WithFields(fields map[string]any) Logger
WithFields provides additional fields to include in log output