ucplog

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLoggerName string = "radius"
	LogLevel          string = "RADIUS_LOGGING_LEVEL" // Env variable that determines the log level
	LogProfile        string = "RADIUS_LOGGING_JSON"  // Env variable that determines the logger config presets
)

Radius uses the Zapr: https://github.com/go-logr/zapr which implements a logr interface for a zap log sink

View Source
const (

	// LevelInfo is the default.
	LevelInfo int = 0

	// LevelDebug should be used for messages that should not be shown in production.
	LevelDebug int = 1
)

Log levels

View Source
const (
	VerbosityLevelInfo  string = "INFO"
	VerbosityLevelDebug string = "DEBUG"
	VerbosityLevelError string = "ERROR"
	VerbosityLevelWarn  string = "WARN"
)
View Source
const (
	LoggerProfileProd    string = "production"
	LoggerProfileDev     string = "development"
	DefaultLoggerProfile        = LoggerProfileDev
)

Logger Profiles which determines the logger configuration

View Source
const (
	LoggerName  string = "ucplogger"
	ServiceName string = "ucp"
)
View Source
const (
	// LogFieldHostName represents the current hostname.
	LogFieldHostname string = "hostName"

	// LogFieldVersion represents the version of service.
	LogFieldVersion string = "version"

	// LogFieldResourceID represents the Radius Resource ID.
	LogFieldResourceID string = "resourceId"

	// LogFieldTargetResourceID represents the resource ID of a non-Radius resource. eg: an output resource.
	LogFieldTargetResourceID string = "targetResourceID"

	// LogFieldCorrelationID represents the X-Correlation-ID that may be present in the incoming request.
	LogFieldCorrelationID string = "correlationId"

	// LogFieldServiceName represents the name of the service generating the log entry
	LogFieldServiceName string = "serviceName"

	// LogFieldTraceId represents the traceId retrieved from traceparent header of the current HTTP request
	LogFieldTraceId string = "traceId"

	// LogFieldSpanId represents the spanId retrieved from traceparent header of current HTTP request
	LogFieldSpanId string = "spanId"

	// HttpXForwardedFor represents the x-forwarded-for HTTP header
	HttpXForwardedFor string = "x-forwarded-for"

	// HttpCorrelationId represents the x-forwarded-for HTTP header
	HttpCorrelationId string = "x-correlation-id"

	// HttpUserAgent represents the user-agent HTTP header
	HttpUserAgent string = "user-agent"
)

Field names for structured logging

Variables

This section is empty.

Functions

func FromContextOrDiscard

func FromContextOrDiscard(ctx context.Context) logr.Logger

FromContextOrDiscard returns a logger with trace and span IDs populated from the context if they exist. In order to get logger without span, use logr.FromContextOrDiscard(ctx context.Context).

func NewLogger

func NewLogger(name string, options *LoggingOptions) (logr.Logger, func(), error)

NewLogger creates a new logger with zap logger implementation, with the given name and logging options, and returns a function to flush the logs before the server exits.

func NewResourceObject

func NewResourceObject(serviceName string) []any

This function creates a new resource object with the given service name, hostname and version.

func NewTestLogger

func NewTestLogger(t *testing.T) (logr.Logger, error)

NewTestLogger creates a new logger zaptest logger implementation.

func Unwrap

func Unwrap(logger logr.Logger) *zap.Logger

Unwrap attempts to extract the underlying zap.Logger from a logr.Logger, returning nil if it fails.

func WrapLogContext

func WrapLogContext(ctx context.Context, keyValues ...any) context.Context

WrapLogContext adds key-value pairs to the context's logger for logging purposes.

Types

type LoggingOptions

type LoggingOptions struct {
	Json  bool   `yaml:"json"`
	Level string `yaml:"level"`
}

LoggingOptions represents the logger.

Jump to

Keyboard shortcuts

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