log

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WriterConsole console输出
	WriterConsole = "console"
	// WriterFile 文件输出
	WriterFile = "file"
)
View Source
const (
	// RotateTimeDaily 按天切割
	RotateTimeDaily = "daily"
	// RotateTimeHourly 按小时切割
	RotateTimeHourly = "hourly"
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug logger

func Debugf

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

Debugf logger

func Error

func Error(args ...interface{})

Error logger

func Errorf

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

Errorf logger

func Fatal

func Fatal(args ...interface{})

Fatal logger

func Fatalf

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

Fatalf logger

func Info

func Info(args ...interface{})

Info logger

func Infof

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

Infof logger

func Panicf

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

Panicf logger

func Warn

func Warn(args ...interface{})

Warn logger

func Warnf

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

Warnf logger

Types

type Config

type Config struct {
	Development       bool
	DisableCaller     bool
	DisableStacktrace bool
	Encoding          string
	Level             string
	Name              string
	Writers           string
	LoggerFile        string
	LoggerWarnFile    string
	LoggerErrorFile   string
	LogFormatText     bool
	LogRollingPolicy  string
	LogRotateDate     int
	LogRotateSize     int
	LogBackupCount    uint
}

Logger config

type Fields

type Fields map[string]interface{}

Fields Type to pass when we want to call WithFields for structured logging

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})

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

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

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

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

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

	WithFields(keyValues Fields) Logger
}

Logger is our contract for the logger

func GetLogger

func GetLogger() Logger

func Init

func Init(cfg *Config) Logger

Init init log

func WithFields

func WithFields(keyValues Fields) Logger

WithFields logger output more field, eg:

contextLogger := log.WithFields(log.Fields{"key1": "value1"})
contextLogger.Info("print multi field")

or more sample to use:

log.WithFields(log.Fields{"key1": "value1"}).Info("this is a test log")
log.WithFields(log.Fields{"key1": "value1"}).Infof("this is a test log, user_id: %d", userID)

Jump to

Keyboard shortcuts

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