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
- func Clean(ctx context.Context) (context.Context, error)
- func ContextWithTrace(ctx context.Context, traceid string) context.Context
- func DefaultTestLogConfig() configuration.Log
- func FromContext(ctx context.Context) log.Logger
- func GetLoggerLevel(ctx context.Context) log.Level
- func InitGlobalNodeLogger(ctx context.Context, cfg configuration.Log, nodeRef, nodeRole string) (context.Context, log.Logger)
- func InitNodeLogger(ctx context.Context, cfg configuration.Log, nodeRef, nodeRole string) (context.Context, log.Logger)
- func InitNodeLoggerByGlobal(nodeRef, nodeRole string) (context.Context, log.Logger)
- func NewLog(cfg configuration.Log) (logger log.Logger, err error)
- func NewLogBuilder(cfg configuration.Log) (log.LoggerBuilder, error)
- func NewLoglevelChangeHandler() http.Handler
- func ParseFormat(formatStr string) (logcommon.LogFormat, error)
- func ParseFormatDef(formatStr string, defValue logcommon.LogFormat) (logcommon.LogFormat, error)
- func ParseOutput(outputStr string) (logoutput.LogOutput, error)
- func ParseOutputDef(outputStr string, defValue logoutput.LogOutput) (logoutput.LogOutput, error)
- func SetLogger(ctx context.Context, l log.Logger) context.Context
- func TraceField(traceid string) logfmt.LogField
- func TraceID(ctx context.Context) string
- func UpdateLogger(ctx context.Context, fn func(log.Logger) (log.Logger, error)) context.Context
- func WithField(ctx context.Context, key string, value string) (context.Context, log.Logger)
- func WithFields(ctx context.Context, fields map[string]interface{}) (context.Context, log.Logger)
- func WithLoggerLevel(ctx context.Context, logLevel log.Level) context.Context
- func WithTraceField(ctx context.Context, traceid string) (context.Context, log.Logger)
- type ParsedLogConfig
Constants ¶
View Source
const TimestampFormat = prettylog.TimestampFormat
Variables ¶
This section is empty.
Functions ¶
func ContextWithTrace ¶
ContextWithTrace returns only context with logger initialized with provided traceid.
func DefaultTestLogConfig ¶
func DefaultTestLogConfig() configuration.Log
func FromContext ¶
FromContext returns logger from context.
func InitGlobalNodeLogger ¶
func InitNodeLogger ¶
func InitNodeLoggerByGlobal ¶
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 ¶
ServeHTTP is an HTTP handler that changes the global minimum log level
func ParseFormatDef ¶
func ParseOutputDef ¶
func TraceField ¶
func UpdateLogger ¶
func WithField ¶
WithField returns context with logger initialized with provided field's key value and logger itself.
func WithFields ¶
WithFields returns context with logger initialized with provided fields map.
func WithLoggerLevel ¶
SetLoggerLevel and set logLevel on logger and returns context with the new logger
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)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.