elog

package module
v0.0.0-...-a95724a Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

README

elog

Go logging library

Documentation

Index

Constants

View Source
const (
	JSON = "json"
	Text = "text"
)
View Source
const (
	Console = "console"
)

Variables

This section is empty.

Functions

func AddOutput

func AddOutput(name string, cfg *OutputConfig) error

func Debug

func Debug(args ...interface{})

elog writers

func Debugf

func Debugf(format string, args ...interface{})

printf-like

func Debugw

func Debugw(msg string, kvs ...interface{})

elog key values

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorw

func Errorw(msg string, kvs ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalw

func Fatalw(msg string, kvs ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infow

func Infow(msg string, kvs ...interface{})

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicw

func Panicw(msg string, kvs ...interface{})

func Printf

func Printf(format string, args ...interface{})

func Println

func Println(args ...interface{})

func RegisterOutput

func RegisterOutput(name string, constructor Constructor) error

func SetLevel

func SetLevel(level Level)

func Sync

func Sync() error

Sync flush logs

func Use

func Use(logger Logger)

Use sets global logger

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warnw

func Warnw(msg string, kvs ...interface{})

func WithContext

func WithContext(ctx context.Context, logger Logger) context.Context

Types

type Config

type Config struct {
	Level             string                   `json:"level,omitempty" yaml:"level"`
	Name              string                   `json:"name" yaml:"name"`
	CallerDisabled    bool                     `json:"callerDisabled,omitempty" yaml:"callerDisabled"`
	StacktraceEnabled bool                     `json:"stacktraceEnabled,omitempty" yaml:"stacktraceEnabled"`
	Encoding          string                   `json:"encoding,omitempty" yaml:"encoding"`
	EncoderConfig     *EncoderConfig           `json:"encoderConfig,omitempty" yaml:"encoderConfig"`
	InitialFields     map[string]interface{}   `json:"initialFields,omitempty" yaml:"initialFields"`
	Output            map[string]*OutputConfig `json:"output" yaml:"output"`
}

func DefaultConfig

func DefaultConfig() *Config

type Constructor

type Constructor func(cfg *OutputConfig) (Output, error)

type EncoderConfig

type EncoderConfig struct {
	ColorEnabled    bool   `json:"colorEnabled" yaml:"colorEnabled"`
	MessageKey      string `json:"messageKey,omitempty" yaml:"messageKey"`
	LevelKey        string `json:"levelKey,omitempty" yaml:"levelKey"`
	TimeKey         string `json:"timeKey,omitempty" yaml:"timeKey"`
	NameKey         string `json:"nameKey,omitempty" yaml:"nameKey"`
	CallerKey       string `json:"callerKey,omitempty" yaml:"callerKey"`
	StacktraceKey   string `json:"stacktraceKey,omitempty" yaml:"stacktraceKey"`
	LineEnding      string `json:"lineEnding,omitempty" yaml:"lineEnding"`
	LevelEncoder    string `json:"levelEncoder,omitempty" yaml:"levelEncoder"`
	TimeEncoder     string `json:"timeEncoder,omitempty" yaml:"timeEncoder"`
	DurationEncoder string `json:"durationEncoder,omitempty" yaml:"durationEncoder"`
	CallerEncoder   string `json:"callerEncoder,omitempty" yaml:"callerEncoder"`
	NameEncoder     string `json:"nameEncoder,omitempty" yaml:"nameEncoder"`
}

func DefaultEncoderConfig

func DefaultEncoderConfig() *EncoderConfig

type Level

type Level int8
const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	PANIC
	FATAL
)

func ParseLevel

func ParseLevel(levelStr string) (l Level, err error)

type Logger

type Logger interface {
	SetLevel(levelStr Level)
	Sync() error

	// new loggers
	Named(name string) Logger
	With(kvs ...interface{}) Logger
	AddCallerSkip(skip int) Logger

	AddOutput(name string, cfg *OutputConfig) error

	// elog writers
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	// elog key values
	Debugw(msg string, kvs ...interface{})
	Infow(msg string, kvs ...interface{})
	Warnw(msg string, kvs ...interface{})
	Errorw(msg string, kvs ...interface{})
	Fatalw(msg string, kvs ...interface{})
	Panicw(msg string, kvs ...interface{})

	// printf-like
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Printf(format string, args ...interface{})
	Println(args ...interface{})
}

Logger logger.yaml interface

func AddCallerSkip

func AddCallerSkip(skip int) Logger

func FromContext

func FromContext(ctx context.Context) Logger

func Get

func Get() Logger

Get gets global logger

func Named

func Named(name string) Logger

func New

func New(cfg *Config) Logger

func With

func With(kvs ...interface{}) Logger

type Output

type Output interface {
	io.Closer
	Write(level Level, line []byte) error
	Sync() error
}

type OutputConfig

type OutputConfig struct {
	Enabled       bool                   `json:"enabled,omitempty" yaml:"enabled"`
	Level         string                 `json:"level,omitempty" yaml:"level"`
	Encoding      string                 `json:"encoding,omitempty" yaml:"encoding"`
	EncoderConfig *EncoderConfig         `json:"encoderConfig,omitempty" yaml:"encoderConfig"`
	Params        map[string]interface{} `json:"parameters,omitempty" yaml:"parameters"`
}

func DefaultConsoleConfig

func DefaultConsoleConfig() *OutputConfig

Directories

Path Synopsis
examples
internal
output

Jump to

Keyboard shortcuts

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