Documentation
¶
Overview ¶
Package log span logger for trace reference: https://github.com/jaegertracing/jaeger/tree/master/examples/hotrod/pkg/log
Index ¶
- Constants
- Variables
- 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
- type RouterLogger
- func (l *RouterLogger) Debug(args ...interface{})
- func (l *RouterLogger) Debugf(format string, args ...interface{})
- func (l *RouterLogger) Error(args ...interface{})
- func (l *RouterLogger) Errorf(format string, args ...interface{})
- func (l *RouterLogger) Fatal(args ...interface{})
- func (l *RouterLogger) Fatalf(format string, args ...interface{})
- func (l *RouterLogger) Info(args ...interface{})
- func (l *RouterLogger) Infof(format string, args ...interface{})
- func (l *RouterLogger) Log(level klog.Level, keyvals ...interface{}) error
- func (l *RouterLogger) Panicf(format string, args ...interface{})
- func (l *RouterLogger) Sugared() *zap.SugaredLogger
- func (l *RouterLogger) Sync() error
- func (l *RouterLogger) Warn(args ...interface{})
- func (l *RouterLogger) Warnf(format string, args ...interface{})
- func (l *RouterLogger) WithFields(fields Fields) Logger
- func (l *RouterLogger) WithKey(key string) *zap.SugaredLogger
- type RouterLoggerConfig
Constants ¶
View Source
const ( // WriterConsole console输出 WriterConsole = "console" // WriterFile 文件输出 WriterFile = "file" )
View Source
const ( // RotateTimeDaily 按天切割 RotateTimeDaily = "daily" // RotateTimeHourly 按小时切割 RotateTimeHourly = "hourly" )
Variables ¶
View Source
var DefaultLoggerKey = "default"
Functions ¶
func GetLogFile ¶
GetLogFile get log file absolute path
Types ¶
type Config ¶
type Config struct {
Development bool
DisableCaller bool
DisableStacktrace bool
Encoding string
ServiceName string // service name
Level string
Filename string
Writers string // file or console or all
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 NewLoggerHelper ¶
func NewLoggerHelper() 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)
type RouterLogger ¶
type RouterLogger struct {
// contains filtered or unexported fields
}
func NewRouterLogger ¶
func NewRouterLogger(cfg *RouterLoggerConfig) *RouterLogger
func (*RouterLogger) Debug ¶
func (l *RouterLogger) Debug(args ...interface{})
func (*RouterLogger) Debugf ¶
func (l *RouterLogger) Debugf(format string, args ...interface{})
func (*RouterLogger) Error ¶
func (l *RouterLogger) Error(args ...interface{})
func (*RouterLogger) Errorf ¶
func (l *RouterLogger) Errorf(format string, args ...interface{})
func (*RouterLogger) Fatal ¶
func (l *RouterLogger) Fatal(args ...interface{})
func (*RouterLogger) Fatalf ¶
func (l *RouterLogger) Fatalf(format string, args ...interface{})
func (*RouterLogger) Info ¶
func (l *RouterLogger) Info(args ...interface{})
func (*RouterLogger) Infof ¶
func (l *RouterLogger) Infof(format string, args ...interface{})
func (*RouterLogger) Log ¶
func (l *RouterLogger) Log(level klog.Level, keyvals ...interface{}) error
func (*RouterLogger) Panicf ¶
func (l *RouterLogger) Panicf(format string, args ...interface{})
func (*RouterLogger) Sugared ¶
func (l *RouterLogger) Sugared() *zap.SugaredLogger
func (*RouterLogger) Sync ¶
func (l *RouterLogger) Sync() error
func (*RouterLogger) Warn ¶
func (l *RouterLogger) Warn(args ...interface{})
func (*RouterLogger) Warnf ¶
func (l *RouterLogger) Warnf(format string, args ...interface{})
func (*RouterLogger) WithFields ¶
func (l *RouterLogger) WithFields(fields Fields) Logger
func (*RouterLogger) WithKey ¶
func (l *RouterLogger) WithKey(key string) *zap.SugaredLogger
type RouterLoggerConfig ¶
func ConvertConfiguration ¶
func ConvertConfiguration(conf interface{}) *RouterLoggerConfig
Click to show internal directories.
Click to hide internal directories.