log

package
v0.0.0-...-a423d60 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 15 Imported by: 32

Documentation

Index

Constants

View Source
const (
	// FieldRequestID represent the request ID field name in the logger derived from the istio 'x-request-id' header
	FieldRequestID = "x-request-id"

	// FieldTraceID represent the trace ID field name in the logger derived from the istio 'x-b3-traceid' header
	FieldTraceID = "x-trace-id"

	// FieldSpanID represent the span ID field name in the logger derived from the istio 'x-b3-spanid' header
	FieldSpanID = "x-span-id"

	// FieldParentSpanID represent the parent span ID field name in the logger derived from the istio 'x-b3-parentspanid' header
	FieldParentSpanID = "x-parent-span-id"

	// FieldFormationID represent the formation field name in the logger
	FieldFormationID = "formation-id"

	// FieldFormationAssignmentID represent the formation assignment field name in the logger
	FieldFormationAssignmentID = "formation-assignment-id"
)

Variables

View Source
var (

	// C missing godoc
	C = LoggerFromContext
	// D missing godoc
	D = DefaultLogger
)

Functions

func AddCorrelationIDsToLogger

func AddCorrelationIDsToLogger(ctx context.Context, correlationID, traceID, spanID, parentSpanID string) *logrus.Entry

AddCorrelationIDsToLogger adds all correlation IDs to the logger

func AddHook

func AddHook(hook logrus.Hook)

AddHook adds a hook to all loggers

func Configure

func Configure(ctx context.Context, config *Config) (context.Context, error)

Configure creates a new context with a logger using the provided settings.

func ContextWithLogger

func ContextWithLogger(ctx context.Context, entry *logrus.Entry) context.Context

ContextWithLogger returns a new context with the provided logger.

func ContextWithMdc

func ContextWithMdc(ctx context.Context) context.Context

ContextWithMdc returns a new context with attached MDC

func DefaultLogger

func DefaultLogger() *logrus.Entry

DefaultLogger returns the default logger

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *logrus.Entry

LoggerFromContext retrieves the current logger from the context.

func LoggerWithCorrelationID

func LoggerWithCorrelationID(r *http.Request) *logrus.Entry

LoggerWithCorrelationID missing godoc

func LoggerWithParentSpanID

func LoggerWithParentSpanID(r *http.Request, entry *logrus.Entry) *logrus.Entry

LoggerWithParentSpanID adds the parent span ID to the logger

func LoggerWithSpanID

func LoggerWithSpanID(r *http.Request, entry *logrus.Entry) *logrus.Entry

LoggerWithSpanID adds the span ID to the logger

func LoggerWithTraceID

func LoggerWithTraceID(r *http.Request, entry *logrus.Entry) *logrus.Entry

LoggerWithTraceID adds the trace ID to the logger

func NewGqlLoggingInterceptor

func NewGqlLoggingInterceptor() *opsInterceptor

NewGqlLoggingInterceptor creates a new opsInterceptor instance

func RegisterFormatter

func RegisterFormatter(name string, formatter logrus.Formatter) error

RegisterFormatter registers a new logrus Formatter with the given name. Returns an error if there is a formatter with the same name.

func RequestLogger

func RequestLogger(pathsToLogOnDebug ...string) func(next http.Handler) http.Handler

RequestLogger returns middleware that setups request scoped logging. URL paths starting with pathsToLogOnDebug will be logged on debug instead of info.

Types

type Config

type Config struct {
	Level                  string `envconfig:"APP_LOG_LEVEL,default=info"`
	Format                 string `envconfig:"APP_LOG_FORMAT,default=text"`
	Output                 string `envconfig:"APP_LOG_OUTPUT,default=/dev/stdout"`
	BootstrapCorrelationID string `envconfig:"APP_LOG_BOOTSTRAP_CORRELATION_ID,default=bootstrap"`
}

Config missing godoc

func Configuration

func Configuration() Config

Configuration returns the logger settings

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default values for Log settings

func (*Config) Validate

func (s *Config) Validate() error

Validate validates the logging settings

type ErrorLocationHook

type ErrorLocationHook struct {
}

ErrorLocationHook provides an implementation of the sirupsen/logrus/Hook interface. Attaches error location information to log entries if an error is being logged and it has stack-trace information (i.e. if it originates from or is wrapped by github.com/pkg/errors).

func (*ErrorLocationHook) Fire

func (h *ErrorLocationHook) Fire(entry *logrus.Entry) error

Fire missing godoc

func (*ErrorLocationHook) Levels

func (h *ErrorLocationHook) Levels() []logrus.Level

Levels missing godoc

type MDC

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

MDC provides a mechanism to enrich the log messages with information, which might not be available at the time/scope where the logging actually occurs.

func MdcFromContext

func MdcFromContext(ctx context.Context) *MDC

MdcFromContext returns the attached *MDC or nil if there is none

func NewMappedDiagnosticContext

func NewMappedDiagnosticContext() *MDC

NewMappedDiagnosticContext creates a new MDC instance

func (*MDC) Set

func (mdc *MDC) Set(key string, value interface{})

Set adds or overwrites a key-value pair in the MDC

func (*MDC) SetIfNotEmpty

func (mdc *MDC) SetIfNotEmpty(key string, value string)

SetIfNotEmpty adds or overwrites a key-value pair in the MDC but only if the value is not empty

Jump to

Keyboard shortcuts

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