log

package
v0.0.0-...-213805d Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 9 Imported by: 0

README

Sample usage

// using default logger
log.Info(context.Background(), "test info log", errors.New("test error"), log.KV{
    "data1": 123,
    "data2": "data 2 content",
})
log.Printf("sample data, value:%d", 123)

// override default logger
log.SetLogger(log.NewZerolog(log.Config{
    LogLevel:       log.LogLevelTrace,
    TimeFormat:     log.LogTimeFormatTimestamp,
    OutputType:     log.OutputFile,
    OutputFilePath: "test.log",
}))
log.Info(context.Background(), "test debug log123123", errors.New("test error"), log.KV{
    "data3": 111,
    "data4": "data 4 content",
})

Documentation

Index

Constants

View Source
const (
	LogLevelUnknown = iota
	LogLevelTrace
	LogLevelDebug
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelPanic
	LogLevelFatal
)
View Source
const (
	LogTimeFormatDisable = iota
	LogTimeFormatUnix
	LogTimeFormatTimestamp
)
View Source
const (
	OutputStdout = iota
	OutputStderr
	OutputFile
)

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string, err error, fields KV)

func Error

func Error(ctx context.Context, msg string, err error, fields KV)

func Fatal

func Fatal(ctx context.Context, msg string, err error, fields KV)

func Info

func Info(ctx context.Context, msg string, err error, fields KV)

func Panic

func Panic(ctx context.Context, msg string, err error, fields KV)

func Print

func Print(msg string)

func Printf

func Printf(msg string, v ...any)

func SetLogger

func SetLogger(log Log)

func Trace

func Trace(ctx context.Context, msg string, err error, fields KV)

func Warn

func Warn(ctx context.Context, msg string, err error, fields KV)

Types

type Config

type Config struct {
	LogLevel       LogLevel
	TimeFormat     LogTimeFormat
	OutputType     Output
	OutputFilePath string // only if output type is set to OutputFile
}

type KV

type KV map[string]any

type Log

type Log interface {
	Print(msg string)
	Printf(msg string, v ...any)

	Trace(ctx context.Context, msg string, err error, fields KV)
	Info(ctx context.Context, msg string, err error, fields KV)
	Warn(ctx context.Context, msg string, err error, fields KV)
	Error(ctx context.Context, msg string, err error, fields KV)
	Debug(ctx context.Context, msg string, err error, fields KV)
	Panic(ctx context.Context, msg string, err error, fields KV)
	Fatal(ctx context.Context, msg string, err error, fields KV)
}

func NewZaplog

func NewZaplog(cfg Config) Log

func NewZerolog

func NewZerolog(cfg Config) Log

type LogLevel

type LogLevel int

type LogTimeFormat

type LogTimeFormat int

type Output

type Output int

Jump to

Keyboard shortcuts

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