Documentation ¶
Index ¶
- Constants
- func FromContextOrDiscard(ctx context.Context) logr.Logger
- func NewLogger(name string, options *LoggingOptions) (logr.Logger, func(), error)
- func NewResourceObject(serviceName string) []any
- func NewTestLogger(t *testing.T) (logr.Logger, error)
- func Unwrap(logger logr.Logger) *zap.Logger
- func WrapLogContext(ctx context.Context, keyValues ...any) context.Context
- type LoggingOptions
Constants ¶
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
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
const ( VerbosityLevelInfo string = "INFO" VerbosityLevelDebug string = "DEBUG" VerbosityLevelError string = "ERROR" VerbosityLevelWarn string = "WARN" )
const ( LoggerProfileProd string = "production" LoggerProfileDev string = "development" DefaultLoggerProfile = LoggerProfileDev )
Logger Profiles which determines the logger configuration
const ( LoggerName string = "ucplogger" ServiceName string = "ucp" )
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 ¶
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 ¶
This function creates a new resource object with the given service name, hostname and version.
func NewTestLogger ¶
NewTestLogger creates a new logger zaptest logger implementation.
Types ¶
type LoggingOptions ¶
LoggingOptions represents the logger.