Documentation
¶
Overview ¶
Package log span logger for trace reference: https://github.com/jaegertracing/jaeger/tree/master/examples/hotrod/pkg/log
Index ¶
- Constants
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func GetLogFile(filename string, suffix string) string
- func GetZapLogger() *zap.Logger
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Config
- type Fields
- type Logger
- type Option
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 GetLogFile ¶ added in v1.8.0
GetLogFile get log file absolute path
func GetZapLogger ¶ added in v1.6.0
GetZapLogger return raw zap logger
Types ¶
type Config ¶
type Config struct {
Development bool
DisableCaller bool
DisableStacktrace bool
Encoding string
Level string
ServiceName string // service name
Filename string
Writers string
LoggerDir string
LogFormatText bool
LogRollingPolicy string
LogBackupCount uint
FlushInterval time.Duration // default is 30s, recommend is dev or test is 1s, prod is 1m
}
Config log 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 logs a message at Fatal level
// and process will exit with status set to 1.
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
WithFields(keyValues Fields) Logger
}
Logger is a contract for the logger
func WithContext ¶
WithContext is a logger that can log msg and log span for trace
func WithFields ¶
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)
Click to show internal directories.
Click to hide internal directories.