Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(msg string, keysAndVals ...interface{})
- func Debugf(format string, args ...interface{})
- func EnableNativeTime()
- func EnabledNativeTime() bool
- func Error(msg string, keysAndVals ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(msg string, keysAndVals ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(msg string, keysAndVals ...interface{})
- func Infof(format string, args ...interface{})
- func LoadConfig(path string) error
- func Panic(msg string, keysAndVals ...interface{})
- func Panicf(format string, args ...interface{})
- func ResetConfigs()
- func SetCallerLevels(levels ...Level)
- func SetEncoding(encoding Encoding)
- func SetJSONEncoderConfig(cfg JSONEncoderConfig)
- func SetLevel(level Level)
- func SetModuleConfig(module string, cfg Config)
- func SetStacktraceLevels(levels ...Level)
- func SetTextEncoderConfig(cfg TextEncoderConfig)
- func SetWriter(writer io.Writer)
- func Warn(msg string, keysAndVals ...interface{})
- func Warnf(format string, args ...interface{})
- type Config
- type Configs
- type Encoder
- type Encoding
- type Entry
- func (e *Entry) Bytes() []byte
- func (e *Entry) CallerSkip() int
- func (e *Entry) FieldsLength() int
- func (e *Entry) GetCaller() string
- func (e *Entry) HasFlag(flag Flag) bool
- func (e *Entry) Reset()
- func (e *Entry) SetCaller(caller string)
- func (e *Entry) SetCallerSkip(n int)
- func (e *Entry) SetFieldsLen(n int)
- func (e *Entry) SetFlag(flag Flag)
- func (e *Entry) Write(p []byte) (int, error)
- func (e *Entry) WriteByte(c byte) error
- func (e *Entry) WriteString(s string) (int, error)
- func (e *Entry) WriteTo(w io.Writer) (int64, error)
- type Field
- type File
- type FileConfig
- type Flag
- type HandlerConfig
- type JSONEncoder
- type JSONEncoderConfig
- type Level
- type Log
- func (l *Log) CallerSkip(skip int) *Log
- func (l *Log) Debug(msg string, keysAndVals ...interface{})
- func (l *Log) Debugf(format string, args ...interface{})
- func (l *Log) Error(msg string, keysAndVals ...interface{})
- func (l *Log) Errorf(format string, args ...interface{})
- func (l *Log) Fatal(msg string, keysAndVals ...interface{})
- func (l *Log) Fatalf(format string, args ...interface{})
- func (l *Log) Info(msg string, keysAndVals ...interface{})
- func (l *Log) Infof(format string, args ...interface{})
- func (l *Log) Panic(msg string, keysAndVals ...interface{})
- func (l *Log) Panicf(format string, args ...interface{})
- func (l *Log) Warn(msg string, keysAndVals ...interface{})
- func (l *Log) Warnf(format string, args ...interface{})
- func (l *Log) WithValues(keysAndVals ...interface{}) Logger
- type Logger
- type RotateFile
- type RotateFileConfig
- type TextEncoder
- type TextEncoderConfig
Constants ¶
const ( // TimestampFieldName is the field name used for the timestamp field. TimestampFieldName = "time" // LevelFieldName is the field name used for the level field. LevelFieldName = "level" // ModuleFieldName is the field name used for the module field. ModuleFieldName = "module" // MessageFieldName is the field name used for the message field. MessageFieldName = "message" // ErrorFieldName is the field name used for error fields. ErrorFieldName = "error" // CallerFieldName is the field name used for caller field. CallerFieldName = "caller" // ErrorStackFieldName is the field name used for error stacks. ErrorStackFieldName = "stack" // TimeFieldFormat defines the time format of the Time field type. If set to // TimeFormatUnix, TimeFormatUnixMs or TimeFormatUnixMicro, the time is formatted as an UNIX // timestamp as integer. TimeFieldFormat = time.RFC3339 )
const DefaultLineEnding = '\n'
DefaultLineEnding is the default line ending used by the text encoder.
Variables ¶
var ( //DefaultCallerSkip is the default number of stack frames to skip when reporting caller information. DefaultCallerSkip int = 3 // ErrorMarshalFunc allows customization of global error marshaling ErrorMarshalFunc = func(err error) interface{} { return err } )
Functions ¶
func Debug ¶ added in v1.1.0
func Debug(msg string, keysAndVals ...interface{})
Debug logs a message using Debug level.
func Debugf ¶ added in v1.2.0
func Debugf(format string, args ...interface{})
Debugf logs a message using Debug level.
func EnableNativeTime ¶ added in v1.6.2
func EnableNativeTime()
EnableNativeTime - enable native time
func EnabledNativeTime ¶ added in v1.6.2
func EnabledNativeTime() bool
EnabledNativeTime - check if native time is enabled
func Error ¶ added in v1.1.0
func Error(msg string, keysAndVals ...interface{})
Error logs a message using Error level.
func Errorf ¶ added in v1.2.0
func Errorf(format string, args ...interface{})
Errorf logs a message using Error level.
func Fatal ¶ added in v1.1.0
func Fatal(msg string, keysAndVals ...interface{})
Fatal logs a message using Fatal level and exits with status 1.
func Fatalf ¶ added in v1.2.0
func Fatalf(format string, args ...interface{})
Fatalf logs a message using Fatal level and exits with status 1.
func Info ¶ added in v1.1.0
func Info(msg string, keysAndVals ...interface{})
Info logs a message using Info level.
func Infof ¶ added in v1.2.0
func Infof(format string, args ...interface{})
Infof logs a message using Info level.
func LoadConfig ¶ added in v1.5.0
LoadConfig - load config from file.
func Panic ¶ added in v1.4.0
func Panic(msg string, keysAndVals ...interface{})
Panic logs a message using Panic level and panics.
func Panicf ¶ added in v1.2.1
func Panicf(format string, args ...interface{})
Panicf logs a message using Panic level and panics.
func SetCallerLevels ¶ added in v1.5.3
func SetCallerLevels(levels ...Level)
SetCallerLevels - set caller levels.
func SetEncoding ¶ added in v1.5.3
func SetEncoding(encoding Encoding)
SetEncoding - set log encoding.
func SetJSONEncoderConfig ¶ added in v1.5.3
func SetJSONEncoderConfig(cfg JSONEncoderConfig)
SetJSONEncoderConfig - set json encoder config.
func SetModuleConfig ¶ added in v1.5.2
SetModuleConfig - setting config for given module.
func SetStacktraceLevels ¶ added in v1.5.3
func SetStacktraceLevels(levels ...Level)
SetStacktraceLevels - set stacktrace levels.
func SetTextEncoderConfig ¶ added in v1.5.6
func SetTextEncoderConfig(cfg TextEncoderConfig)
SetTextEncoderConfig - set text encoder config.
Types ¶
type Config ¶ added in v1.5.1
type Config struct {
// Level is the default log level.
Level Level `json:"level" yaml:"level"`
// Encoding is the log encoding. text or json.
Encoding Encoding `json:"encoding" yaml:"encoding"`
TextEncoder TextEncoderConfig `json:"textEncoder" yaml:"textEncoder"`
JSONEncoder JSONEncoderConfig `json:"jsonEncoder" yaml:"jsonEncoder"`
//CallerLevels is the default levels for show caller info.
CallerLevels []Level `json:"callerLevels" yaml:"callerLevels"`
// StacktraceLevels is the default levels for show stacktrace.
StacktraceLevels []Level `json:"stacktraceLevels" yaml:"stacktraceLevels"`
Handler HandlerConfig `json:"handler" yaml:"handler"`
}
Config is a configuration for a logger.
func GetModuleConfig ¶ added in v1.5.1
GetModuleConfig - getting config for given module.
type Configs ¶ added in v1.5.1
type Configs struct {
Default Config `json:"default" yaml:"default"`
Modules map[string]Config `json:"modules" yaml:"modules"`
}
Configs - configs for golog.
func GetConfigs ¶ added in v1.6.1
func GetConfigs() *Configs
type Entry ¶
type Entry struct {
Module string
Message string
Data []byte
Level Level
Fields []Field
// contains filtered or unexported fields
}
func (*Entry) CallerSkip ¶ added in v1.5.1
CallerSkip returns the caller skip.
func (*Entry) FieldsLength ¶ added in v1.3.0
FieldsLength returns the number of fields.
func (*Entry) SetCallerSkip ¶ added in v1.5.1
SetCallerSkip sets the caller skip.
func (*Entry) SetFieldsLen ¶ added in v1.5.1
SetFieldsLen sets the number of fields.
func (*Entry) WriteString ¶
WriteString appends the string to the entry data.
type Field ¶ added in v1.1.0
type Field struct {
Key string
Val interface{}
}
Field is a key/value pair.
type File ¶ added in v1.5.1
type File struct {
// contains filtered or unexported fields
}
File is an implementation of io.Writer interface.
func NewFile ¶ added in v1.5.1
func NewFile(cfg FileConfig) (*File, error)
NewFile creates and returns a new File writer.
type FileConfig ¶ added in v1.5.1
type FileConfig struct {
Path string `json:"path" yaml:"path"`
}
FileConfig is a configuration for a file writer.
type HandlerConfig ¶ added in v1.5.6
type HandlerConfig struct {
Type string `json:"type" yaml:"type"`
Writer io.Writer `json:"-" yaml:"-"`
File FileConfig `json:"file" yaml:"file"`
RotateFile RotateFileConfig `json:"rotateFile" yaml:"rotateFile"`
}
HandlerConfig is a configuration for a writer.
type JSONEncoder ¶ added in v1.5.1
type JSONEncoder struct {
// contains filtered or unexported fields
}
JSONEncoder encodes entries as JSON.
func NewJSONEncoder ¶ added in v1.5.1
func NewJSONEncoder(cfg JSONEncoderConfig) *JSONEncoder
NewJSONEncoder returns a new JSONEncoder.
type JSONEncoderConfig ¶ added in v1.5.1
type JSONEncoderConfig struct {
// TimeFormat specifies the format for timestamp in output.
TimeFormat string `json:"timeFormat" yaml:"timeFormat"`
// DisableTimestamp disables the timestamp in output.
DisableTimestamp bool `json:"disableTimestamp" yaml:"disableTimestamp"`
// CallerSkipFrame is the number of stack frames to skip when reporting the calling function.
CallerSkipFrame int `json:"callerSkipFrame" yaml:"callerSkipFrame"`
// ShowModuleName shows the name of the logger.
ShowModuleName bool `json:"showModuleName" yaml:"showModuleName"`
}
JSONEncoderConfig is the configuration for the JSONEncoder.
type Level ¶
type Level uint32
Level is a log level for a logging message.
func (Level) MarshalYAML ¶ added in v1.5.1
MarshalYAML implements the yaml.Marshaler interface.
func (*Level) UnmarshalYAML ¶ added in v1.5.1
UnmarshalYAML implements the yaml.Unmarshaler interface.
type Log ¶ added in v1.5.1
type Log struct {
// contains filtered or unexported fields
}
Log is an implementation of Logger interface. It encapsulates default or custom logger to provide module and level based logging.
func New ¶ added in v1.4.1
New creates and returns a Logger implementation based on given module name.
func NewLoggerByConfig ¶ added in v1.5.0
NewLoggerByConfig creates and returns a Logger implementation based on given config.
func (*Log) CallerSkip ¶ added in v1.5.1
CallerSkip is used to set the number of caller frames to skip.
func (*Log) WithValues ¶ added in v1.5.1
WithValues returns a logger configured with the key-value pairs.
type Logger ¶
type Logger interface {
WithValues(keysAndVals ...interface{}) Logger
Panicf(msg string, args ...interface{})
Fatalf(msg string, args ...interface{})
Errorf(msg string, args ...interface{})
Warnf(msg string, args ...interface{})
Infof(msg string, args ...interface{})
Debugf(msg string, args ...interface{})
Panic(msg string, keysAndVals ...interface{})
Fatal(msg string, keysAndVals ...interface{})
Error(msg string, keysAndVals ...interface{})
Warn(msg string, keysAndVals ...interface{})
Info(msg string, keysAndVals ...interface{})
Debug(msg string, keysAndVals ...interface{})
}
Logger represents a general-purpose logger.
func WithValues ¶ added in v1.5.1
func WithValues(keysAndVals ...interface{}) Logger
WithValues returns a logger configured with the key-value pairs.
type RotateFile ¶ added in v1.5.6
type RotateFile struct {
// contains filtered or unexported fields
}
RotateFile rotate log to file
func NewRotateFile ¶ added in v1.5.6
func NewRotateFile(cfg RotateFileConfig) (*RotateFile, error)
NewRotateFile creates a new RotateFile.
func (*RotateFile) Close ¶ added in v1.5.6
func (f *RotateFile) Close() error
Close implements io.Closer, and closes the current logfile.
func (*RotateFile) Filename ¶ added in v1.5.6
func (f *RotateFile) Filename() string
Filename generates the name of the logfile from the current time.
func (*RotateFile) Rotate ¶ added in v1.5.6
func (f *RotateFile) Rotate() error
Rotate close the existing log file and create a new one.
type RotateFileConfig ¶ added in v1.5.6
type RotateFileConfig struct {
// Filename is the file to write logs to. Backup log files will be retained in the same directory.
// It uses <processname>.log in os.TempDir() if empty.
Filename string `json:"filename" yaml:"filename"`
// MaxBackups is the maximum number of old log files to retain.
MaxBackups int `json:"maxbackups" yaml:"maxbackups"`
// BackupTimeFormat determines if the time used for formatting the backup file name
BackupTimeFormat string `json:"backupTimeFormat" yaml:"backupTimeFormat"`
// LocalTime determines if the time used for formatting the timestamps in
// backup files is the computer's local time. The default is to use UTC
// time.
LocalTime bool `json:"localtime" yaml:"localtime"`
// Async determines if the log write should be async
Async bool `json:"async" yaml:"async"`
}
RotateFileConfig is the configuration for RotateFile.
type TextEncoder ¶ added in v1.5.4
type TextEncoder struct {
// contains filtered or unexported fields
}
TextEncoder encodes entries to the text.
func NewTextEncoder ¶ added in v1.5.4
func NewTextEncoder(cfg TextEncoderConfig) *TextEncoder
NewTextEncoder returns a new text encoder.
type TextEncoderConfig ¶ added in v1.5.4
type TextEncoderConfig struct {
// PartsOrder is the order of the parts of the log entry.
PartsOrder []string `json:"partsOrder" yaml:"partsOrder"`
// TimeFormat specifies the format for timestamp in output.
TimeFormat string `json:"timeFormat" yaml:"timeFormat"`
// DisableTimestamp disables the timestamp in output.
DisableTimestamp bool `json:"disableTimestamp" yaml:"disableTimestamp"`
// DisableColor disables the color in output.
DisableColor bool `json:"disableColor" yaml:"disableColor"`
// CallerSkipFrame is the number of stack frames to skip when reporting the calling function.
CallerSkipFrame int `json:"callerSkipFrame" yaml:"callerSkipFrame"`
// ShowModuleName shows the name of the logger.
ShowModuleName bool `json:"showModuleName" yaml:"showModuleName"`
}
TextEncoderConfig is the configuration for the text encoder.