log

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogKeyMessage    = internal.LogKeyMessage
	LogKeyName       = internal.LogKeyName
	LogKeyTimestamp  = internal.LogKeyTimestamp
	LogKeyCaller     = internal.LogKeyCaller
	LogKeyLevel      = internal.LogKeyLevel
	LogKeyContext    = internal.LogKeyContext
	LogKeyStacktrace = internal.LogKeyStacktrace
)

common fields added by us

View Source
const (
	LevelOffText   = "OFF"
	LevelDebugText = "DEBUG"
	LevelInfoText  = "INFO"
	LevelWarnText  = "WARN"
	LevelErrorText = "ERROR"
)
View Source
const (
	FormatJsonText = "json"
	FormatTextText = "text"
)
View Source
const (
	TypeConsoleText = "console"
	TypeFileText    = "file"
	TypeHttpText    = "http"
	TypeMQText      = "mq"
)

Variables

This section is empty.

Functions

func Capped

func Capped(v interface{}, cap int) string

Capped truncate given value to specified length if cap > 0: with tailing "..." if truncated if cap < 0: with middle "..." if truncated

func DebugShowcase

func DebugShowcase()

func IsTerminal

func IsTerminal(l Logger) bool

func Levels

func Levels(prefix string) (ret map[string]*LevelConfig)

Levels logger level configuration, the returned map's key is the lower case of logger's name

func NewWriterAdapter

func NewWriterAdapter(logger Logger, lvl LoggingLevel) io.Writer

func Padding

func Padding(v interface{}, padding int) string

Padding example: `Padding("some string", -20)`

func RegisterContextLogFields

func RegisterContextLogFields(extractors ...ContextValuers)

func SetLevel

func SetLevel(prefix string, logLevel *LoggingLevel) int

SetLevel set/unset logging level of all loggers with given prefix function returns actual number of affected loggers

func UpdateLoggingConfiguration

func UpdateLoggingConfiguration(properties *Properties) error

Types

type CallerValuer

type CallerValuer interface {
	WithCaller(caller interface{}) Logger
}

type ContextValuer

type ContextValuer func(ctx context.Context) interface{}

type ContextValuers

type ContextValuers map[string]ContextValuer

type Contextual

type Contextual interface {
	WithContext(ctx context.Context) Logger
}

type ContextualLogger

type ContextualLogger interface {
	Logger
	WithContext(ctx context.Context) Logger
}

func New

func New(name string) ContextualLogger

New is the intuitive starting point for any packages to use log package it will create a named logger if a logger with this name doesn't exist yet

type FmtLogger

type FmtLogger interface {
	Debugf(msg string, args ...interface{})
	Infof(msg string, args ...interface{})
	Warnf(msg string, args ...interface{})
	Errorf(msg string, args ...interface{})
}

type Format

type Format int
const (
	FormatText Format
	FormatJson
)

func (Format) MarshalText

func (f Format) MarshalText() ([]byte, error)

encoding.TextMarshaler

func (Format) String

func (f Format) String() string

fmt.Stringer

func (*Format) UnmarshalText

func (f *Format) UnmarshalText(data []byte) error

encoding.TextUnmarshaler

type KVLogger

type KVLogger interface {
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
}

type KeyValuer

type KeyValuer interface {
	WithKV(keyvals ...interface{}) Logger
}

type LevelConfig

type LevelConfig struct {
	Name            string
	EffectiveLevel  *LoggingLevel
	ConfiguredLevel *LoggingLevel
}

LevelConfig is a read-only carrier struct that stores LoggingLevel configuration of each logger

type Leveler

type Leveler interface {
	WithLevel(lvl LoggingLevel) Logger
}

type Logger

type Logger interface {
	FmtLogger
	KVLogger
	KeyValuer
	Leveler
	CallerValuer
	StdLogger
	// Log is go-kit log.Logger interface
	// Deprecated: go-kit is fading out. Use FmtLogger, KVLogger instead
	Log(keyvals ...interface{}) error
}

type LoggerProperties

type LoggerProperties struct {
	Type      LoggerType                `json:"type"`
	Format    Format                    `json:"format"`
	Location  string                    `json:"location"`
	Template  string                    `json:"template"`
	FixedKeys utils.CommaSeparatedSlice `json:"fixed-keys"`
}

LoggerProperties individual logger setup Note:

  1. we currently only support file and console type
  2. "location" is ignored when "type" is "console"
  3. "template" and "fixed-keys" are ignored when "format" is not "text"
  4. "template" is "text/template" compliant template, with "." as log KVs and following added functions: - "{{padding .key -10}}" fixed length stringer - "{{level . 5}}" colored level string with fixed length - "{{coler .key}}" color code (red, green, yellow, gray, cyan) with pipeline support. e.g. "{{padding .msg 20 | red}}"

type LoggerType

type LoggerType int

********************

	LoggerType
 ********************
const (
	TypeConsole LoggerType
	TypeFile
	TypeHttp
	TypeMQ
)

func (LoggerType) MarshalText

func (t LoggerType) MarshalText() ([]byte, error)

encoding.TextMarshaler

func (LoggerType) String

func (t LoggerType) String() string

fmt.Stringer

func (*LoggerType) UnmarshalText

func (t *LoggerType) UnmarshalText(data []byte) error

encoding.TextUnmarshaler

type LoggingLevel

type LoggingLevel int
const (
	LevelOff LoggingLevel = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
)

func (LoggingLevel) MarshalText

func (l LoggingLevel) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (LoggingLevel) String

func (l LoggingLevel) String() string

String implements fmt.Stringer

func (*LoggingLevel) UnmarshalText

func (l *LoggingLevel) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Properties

type Properties struct {
	Levels   map[string]LoggingLevel      `json:"levels"`
	Loggers  map[string]*LoggerProperties `json:"loggers"`
	Mappings map[string]string            `json:"context-mappings"`
}

Properties contains logging settings Note:

  1. "context-mappings" indicate how to map context key to log key, it's map[context-key]log-key

type Stacktracer

type Stacktracer func() (frames []*runtime.Frame, fallback interface{})

func RuntimeCaller

func RuntimeCaller(skip int) Stacktracer

RuntimeCaller equivalent to RuntimeStacktracer(skip, 1)

func RuntimeStacktracer

func RuntimeStacktracer(skip int, depth int) Stacktracer

RuntimeStacktracer find stacktrace frames with runtime package skip: skip certain number of stacks from the top, including the call to the Stacktracer itself depth: max number of stack frames to extract

type StdLogger

type StdLogger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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