belogger

package
v1.0.10-0...-7349ede Latest Latest
Warning

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

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

Documentation

Overview

Package belogger contains context helpers for log

Examples:

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

// get logger from context
log := belogger.FromContext(ctx)

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

Index

Constants

View Source
const TimestampFormat = "2006-01-02T15:04:05.000000000Z07:00"

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) log.Logger

FromContext returns logger from context.

func GetLoggerLevel

func GetLoggerLevel(ctx context.Context) log.Level

func InitLogger

func InitLogger(ctx context.Context, cfg configuration.Log, serviceName 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 NewLoglevelChangeHandler

func NewLoglevelChangeHandler() http.Handler

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

func NewTestLogger

func NewTestLogger(target logcommon.TestingRedirectTarget) log.Logger

func NewTestLoggerExt

func NewTestLoggerExt(target logcommon.TestingRedirectTarget, adapter string) log.Logger

func ParseFormat

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

func ParseOutput

func ParseOutput(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 SetTestOutput

func SetTestOutput(target logcommon.TestingRedirectTarget)

func TestContext

func TestContext(t *testing.T) context.Context

TestContext returns context with initalized log field "testname" equal t.Name() value.

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

Types

type GORMLogAdapter

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

func NewGORMLogAdapter

func NewGORMLogAdapter(log log.Logger) *GORMLogAdapter

func (*GORMLogAdapter) Print

func (l *GORMLogAdapter) Print(values ...interface{})

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)

Jump to

Keyboard shortcuts

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