logx

package module
v0.0.0-...-8e33440 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 3 Imported by: 24

Documentation

Overview

Package logx provides tools to handle log

WithName provides a new logr.Logger:

ctx := context.WithValue(c.Request.Context(), "correlation_id", correlationID) ctx = context.WithValue(ctx, "ipaddress", ip) ctx = context.WithValue(ctx, "kind", "http") log := logx.WithName(ctx, "Test")

GetLogValues returns a keysAndValues model compatible with logrLogger.

var log logr.Logger ctx := context.WithValue(c.Request.Context(), "correlation_id", correlationID) ctx = context.WithValue(ctx, "ipaddress", ip) ctx = context.WithValue(ctx, "kind", "http") kv := logx.GetLogValues(ctx) log = zapr.NewLogger(zapLog) log.Info("test", kv...)

Index

Constants

This section is empty.

Variables

View Source
var FieldString = map[string]Field{
	"correlation_id": CorrelationID,
	"kind":           Kind,
	"method":         Method,
	"ipaddress":      IPAddress,
	"uri":            URI,
}

FieldString match string and Field

Functions

func GetCorrelationID

func GetCorrelationID(ctx context.Context) string

GetCorrelationID get the correlation id from the context or return an empty string

func GetLogValues

func GetLogValues(ctx context.Context) []interface{}

GetLogValues get values from context and return a key/value interface

func WithName

func WithName(ctx context.Context, name string) logr.Logger

WithName provides a new logger with the name appended and values from context

Types

type Field

type Field int

Field is key for logs in context

const (
	// CorrelationID correlation ID key
	CorrelationID Field = iota + 1
	// Kind kind key
	Kind
	// Method http method key
	Method
	// IPAddress ip address key
	IPAddress
	// URI http uri
	URI
)

Jump to

Keyboard shortcuts

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