inslogger

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package inslogger contains context helpers for log

Examples:

// initialize base context with default logger with provided trace id
ctx, inslog := inslogger.WithTraceField(context.Background(), "TraceID")
inslog.Warn("warn")

// get logger from context
inslog := inslogger.FromContext(ctx)

// initalize logger (SomeNewLogger() should return insolar.Logger)
inslogger.SetLogger(ctx, SomeNewLogger())

Hints:

Use environment variables for log level setup:

INSOLAR_LOG_LEVEL=debug INSOLAR_LOG_FORMATTER=text go test ./yourpackage/...

Index

Constants

View Source
const TimestampFormat = prettylog.TimestampFormat

Variables

This section is empty.

Functions

func Clean

func Clean(ctx context.Context) (context.Context, error)

func ContextWithTrace

func ContextWithTrace(ctx context.Context, traceid string) context.Context

ContextWithTrace returns only context with logger initialized with provided traceid.

func DefaultTestLogConfig

func DefaultTestLogConfig() configuration.Log

func FromContext

func FromContext(ctx context.Context) log.Logger

FromContext returns logger from context.

func GetLoggerLevel

func GetLoggerLevel(ctx context.Context) log.Level

func InitGlobalNodeLogger

func InitGlobalNodeLogger(ctx context.Context, cfg configuration.Log, nodeRef, nodeRole string) (context.Context, log.Logger)

func InitNodeLogger

func InitNodeLogger(ctx context.Context, cfg configuration.Log, nodeRef, nodeRole string) (context.Context, log.Logger)

func InitNodeLoggerByGlobal

func InitNodeLoggerByGlobal(nodeRef, nodeRole string) (context.Context, log.Logger)

func NewLog

func NewLog(cfg configuration.Log) (logger log.Logger, err error)

newLog creates a new logger with the given configuration

func NewLogBuilder

func NewLogBuilder(cfg configuration.Log) (log.LoggerBuilder, error)

func NewLoglevelChangeHandler

func NewLoglevelChangeHandler() http.Handler

ServeHTTP is an HTTP handler that changes the global minimum log level

func ParseFormat

func ParseFormat(formatStr string) (logcommon.LogFormat, error)

func ParseFormatDef

func ParseFormatDef(formatStr string, defValue logcommon.LogFormat) (logcommon.LogFormat, error)

func ParseOutput

func ParseOutput(outputStr string) (logoutput.LogOutput, error)

func ParseOutputDef

func ParseOutputDef(outputStr string, defValue logoutput.LogOutput) (logoutput.LogOutput, error)

func SetLogger

func SetLogger(ctx context.Context, l log.Logger) context.Context

SetLogger returns context with provided insolar.Logger,

func TraceField

func TraceField(traceid string) logfmt.LogField

func TraceID

func TraceID(ctx context.Context) string

func UpdateLogger

func UpdateLogger(ctx context.Context, fn func(log.Logger) (log.Logger, error)) context.Context

func WithField

func WithField(ctx context.Context, key string, value string) (context.Context, log.Logger)

WithField returns context with logger initialized with provided field's key value and logger itself.

func WithFields

func WithFields(ctx context.Context, fields map[string]interface{}) (context.Context, log.Logger)

WithFields returns context with logger initialized with provided fields map.

func WithLoggerLevel

func WithLoggerLevel(ctx context.Context, logLevel log.Level) context.Context

SetLoggerLevel and set logLevel on logger and returns context with the new logger

func WithTraceField

func WithTraceField(ctx context.Context, traceid string) (context.Context, log.Logger)

WithTraceField returns context with logger initialized with provided traceid value and logger itself.

Types

type ParsedLogConfig

type ParsedLogConfig struct {
	OutputType logoutput.LogOutput
	LogLevel   log.Level

	OutputParam string

	Output      logcommon.OutputConfig
	Instruments logcommon.InstrumentationConfig

	SkipFrameBaselineAdjustment int8
}

func DefaultLoggerSettings

func DefaultLoggerSettings() ParsedLogConfig

func ParseLogConfig

func ParseLogConfig(cfg configuration.Log) (plc ParsedLogConfig, err error)

func ParseLogConfigWithDefaults

func ParseLogConfigWithDefaults(cfg configuration.Log, defaults ParsedLogConfig) (plc ParsedLogConfig, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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