Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(arguments ...interface{})
- func Debugf(format string, arguments ...interface{})
- func Error(arguments ...interface{})
- func Errorf(format string, arguments ...interface{})
- func Fatal(arguments ...interface{})
- func Fatalf(format string, arguments ...interface{})
- func Info(arguments ...interface{})
- func Infof(format string, arguments ...interface{})
- func NewContext(ctx context.Context, reqID string) context.Context
- func Panic(arguments ...interface{})
- func Panicf(format string, arguments ...interface{})
- func SetConfig(cfg *Config)
- func Warn(arguments ...interface{})
- func Warnf(format string, arguments ...interface{})
- type Config
- type Level
- type Log
- func (l *Log) Caller(frame int) Logger
- func (l *Log) Debug(arguments ...interface{})
- func (l *Log) Debugf(format string, arguments ...interface{})
- func (l *Log) Error(arguments ...interface{})
- func (l *Log) Errorf(format string, arguments ...interface{})
- func (l *Log) Fatal(arguments ...interface{})
- func (l *Log) Fatalf(format string, arguments ...interface{})
- func (l *Log) Info(arguments ...interface{})
- func (l *Log) Infof(format string, arguments ...interface{})
- func (l *Log) Panic(arguments ...interface{})
- func (l *Log) Panicf(format string, arguments ...interface{})
- func (l *Log) SetLevel(level Level) Logger
- func (l *Log) TraceID() string
- func (l *Log) Warn(arguments ...interface{})
- func (l *Log) Warnf(format string, arguments ...interface{})
- func (l *Log) WithContext(ctx ...context.Context) context.Context
- func (l *Log) WithError(err error) Logger
- func (l *Log) WithField(key string, value interface{}) Logger
- func (l *Log) WithFields(fields map[string]interface{}) Logger
- type Logger
Constants ¶
View Source
const (
// TraceIDKey key
TraceIDKey key = 0
)
Variables ¶
View Source
var DefaultGenRequestID func() string = func() string { var b [12]byte binary.LittleEndian.PutUint32(b[:], pid) binary.LittleEndian.PutUint64(b[4:], uint64(time.Now().UnixNano())) return base64.URLEncoding.EncodeToString(b[:]) }
DefaultGenRequestID default generate request id
View Source
var (
// DefaultLogTimeFormat default log time format
DefaultLogTimeFormat = "2006-01-02 15:04:05.000000"
)
View Source
var New func(traceID ...string) Logger = newLogger
New return logger
View Source
var TraceID = "x-request-id"
TraceID is the key for the x-request-id header.
Functions ¶
func NewContext ¶
NewContext return context with reqid
Types ¶
type Config ¶
type Config struct { // log level LogLevel Level `mapstructure:"log_level"` // Enable console logging ConsoleLoggingEnabled bool `mapstructure:"console_logging_enabled"` // EncodeLogsAsJSON makes the log framework log JSON EncodeLogsAsJSON bool `mapstructure:"encode_logs_as_json"` // FileLoggingEnabled makes the framework log to a file, the fields below can be skipped if this value is false! FileLoggingEnabled bool `mapstructure:"file_logging_enabled"` // Filename is the name of the logfile which will be placed inside the directory Filename string `mapstructure:"filename"` // MaxSize the max size in MB of the logfile before it's rolled MaxSize int `mapstructure:"max_size"` // MaxBackups the max number of rolled files to keep MaxBackups int `mapstructure:"max_backups"` // MaxAge the max age in days to keep a logfile MaxAge int `mapstructure:"max_age"` // contains filtered or unexported fields }
Config for logging
type Level ¶
type Level int8
Level type
const ( // DebugLevel defines debug log level. DebugLevel Level = iota // InfoLevel defines info log level. InfoLevel // WarnLevel defines warn log level. WarnLevel // ErrorLevel defines error log level. ErrorLevel // FatalLevel defines fatal log level. FatalLevel // PanicLevel defines panic log level. PanicLevel // NoLevel defines an absent log level. NoLevel // Disabled disables the logger. Disabled // TraceLevel defines trace log level. TraceLevel Level = -1 )
var ( // DefaultLogLevel log level DefaultLogLevel Level = TraceLevel )
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log implement Logger
func (*Log) WithContext ¶
WithContext return context with log
func (*Log) WithFields ¶
WithFields add new fields
type Logger ¶
type Logger interface { // STD log Debug(arguments ...interface{}) Info(arguments ...interface{}) Warn(arguments ...interface{}) Error(arguments ...interface{}) Fatal(arguments ...interface{}) Panic(arguments ...interface{}) Debugf(format string, arguments ...interface{}) Infof(format string, arguments ...interface{}) Warnf(format string, arguments ...interface{}) Errorf(format string, arguments ...interface{}) Fatalf(format string, arguments ...interface{}) Panicf(format string, arguments ...interface{}) // Field logger WithField(key string, value interface{}) Logger WithFields(fields map[string]interface{}) Logger WithError(err error) Logger // Set level SetLevel(level Level) Logger // Caller skip frame count Caller(frame int) Logger // Trace ID TraceID() string // context WithContext(ctx ...context.Context) context.Context }
Logger logger methods
func NewWithContext ¶
NewWithContext return logger with context
func NewWithoutCaller ¶
NewWithoutCaller new log without caller field
Click to show internal directories.
Click to hide internal directories.