logging

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchDecisionIDFromContext added in v1.7.0

func BatchDecisionIDFromContext(ctx context.Context) (string, bool)

func DecisionIDFromContext

func DecisionIDFromContext(ctx context.Context) (string, bool)

func NewContext

func NewContext(parent context.Context, val *RequestContext) context.Context

NewContext returns a copy of parent with an associated RequestContext.

func WithBatchDecisionID added in v1.7.0

func WithBatchDecisionID(parent context.Context, id string) context.Context

func WithDecisionID

func WithDecisionID(parent context.Context, id string) context.Context

func WithHTTPRequestContext

func WithHTTPRequestContext(parent context.Context, val *HTTPRequestContext) context.Context

Types

type HTTPRequestContext

type HTTPRequestContext struct {
	Header http.Header
}

func HTTPRequestContextFromContext

func HTTPRequestContextFromContext(ctx context.Context) (*HTTPRequestContext, bool)

type Level

type Level uint8

Level log level for Logger

const (
	// Error error log level
	Error Level = iota
	// Warn warn log level
	Warn
	// Info info log level
	Info
	// Debug debug log level
	Debug
)

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

type NoOpLogger

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

NoOpLogger logging implementation that does nothing

func NewNoOpLogger

func NewNoOpLogger() *NoOpLogger

NewNoOpLogger instantiates new NoOpLogger

func (*NoOpLogger) Debug

func (*NoOpLogger) Debug(string, ...any)

Debug noop

func (*NoOpLogger) Error

func (*NoOpLogger) Error(string, ...any)

Error noop

func (*NoOpLogger) GetLevel

func (l *NoOpLogger) GetLevel() Level

GetLevel get log level

func (*NoOpLogger) Info

func (*NoOpLogger) Info(string, ...any)

Info noop

func (*NoOpLogger) SetLevel

func (l *NoOpLogger) SetLevel(level Level)

SetLevel set log level

func (*NoOpLogger) Warn

func (*NoOpLogger) Warn(string, ...any)

Warn noop

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 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 New

func New() *StandardLogger

New returns a new standard 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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