Documentation ¶
Index ¶
- Constants
- func Capped(v interface{}, cap int) string
- func DebugShowcase()
- func IsTerminal(l Logger) bool
- func Levels(prefix string) (ret map[string]*LevelConfig)
- func NewWriterAdapter(logger Logger, lvl LoggingLevel) io.Writer
- func Padding(v interface{}, padding int) string
- func RegisterContextLogFields(extractors ...ContextValuers)
- func SetLevel(prefix string, logLevel *LoggingLevel) int
- func UpdateLoggingConfiguration(properties *Properties) error
- type CallerValuer
- type ContextValuer
- type ContextValuers
- type Contextual
- type ContextualLogger
- type FmtLogger
- type Format
- type KVLogger
- type KeyValuer
- type LevelConfig
- type Leveler
- type Logger
- type LoggerProperties
- type LoggerType
- type LoggingLevel
- type Properties
- type Stacktracer
- type StdLogger
Constants ¶
const ( LogKeyMessage = internal.LogKeyMessage LogKeyName = internal.LogKeyName LogKeyTimestamp = internal.LogKeyTimestamp LogKeyCaller = internal.LogKeyCaller LogKeyLevel = internal.LogKeyLevel LogKeyContext = internal.LogKeyContext LogKeyStacktrace = internal.LogKeyStacktrace )
const ( LevelOffText = "OFF" LevelDebugText = "DEBUG" LevelInfoText = "INFO" LevelWarnText = "WARN" LevelErrorText = "ERROR" )
const ( FormatJsonText = "json" FormatTextText = "text" )
const ( TypeConsoleText = "console" TypeFileText = "file" TypeHttpText = "http" TypeMQText = "mq" )
Variables ¶
This section is empty.
Functions ¶
func Capped ¶
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 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 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 ContextValuers ¶
type ContextValuers map[string]ContextValuer
type Contextual ¶
type ContextualLogger ¶
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 Format ¶
type Format int
const ( FormatText Format FormatJson )
func (*Format) UnmarshalText ¶
encoding.TextUnmarshaler
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 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:
- we currently only support file and console type
- "location" is ignored when "type" is "console"
- "template" and "fixed-keys" are ignored when "format" is not "text"
- "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) 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) 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:
- "context-mappings" indicate how to map context key to log key, it's map[context-key]log-key
type Stacktracer ¶
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