Documentation
¶
Index ¶
- Variables
- func NewContext(ctx context.Context, field ...Field) context.Context
- type Factory
- type Field
- func Any(key string, value any) Field
- func Binary(key string, value []byte) Field
- func Bool(key string, value bool) Field
- func Boolp(key string, value *bool) Field
- func Complex128(key string, value complex128) Field
- func Complex128p(key string, value *complex128) Field
- func Complex64(key string, value complex64) Field
- func Complex64p(key string, value *complex64) Field
- func Duration(key string, value time.Duration) Field
- func Durationp(key string, value *time.Duration) Field
- func Error(err error) Field
- func Float32(key string, value float32) Field
- func Float32p(key string, value *float32) Field
- func Float64(key string, value float64) Field
- func Float64p(key string, value *float64) Field
- func Int(key string, value int) Field
- func Int16(key string, value int16) Field
- func Int16p(key string, value *int16) Field
- func Int32(key string, value int32) Field
- func Int32p(key string, value *int32) Field
- func Int64(key string, value int64) Field
- func Int64p(key string, value *int64) Field
- func Int8(key string, value int8) Field
- func Int8p(key string, value *int8) Field
- func Intp(key string, value *int) Field
- func NamedError(key string, err error) Field
- func Stack(key string) Field
- func StackSkip(key string, skip int) Field
- func String(key string, value string) Field
- func Stringer(key string, value fmt.Stringer) Field
- func Stringp(key string, value *string) Field
- func Time(key string, value time.Time) Field
- func Timep(key string, value *time.Time) Field
- func Uint(key string, value uint) Field
- func Uint16(key string, value uint16) Field
- func Uint16p(key string, value *uint16) Field
- func Uint32(key string, value uint32) Field
- func Uint32p(key string, value *uint32) Field
- func Uint64(key string, value uint64) Field
- func Uint64p(key string, value *uint64) Field
- func Uint8(key string, value uint8) Field
- func Uint8p(key string, value *uint8) Field
- func Uintp(key string, value *uint) Field
- func Uintptr(key string, value uintptr) Field
- func Uintptrp(key string, value *uintptr) Field
- type FieldType
- type Level
- type LevelEnabler
- type Logger
Constants ¶
This section is empty.
Variables ¶
var ( LevelName = map[Level]string{ DebugLevel: "DEBUG", InfoLevel: "INFO", WarnLevel: "WARN", ErrorLevel: "ERROR", OffLevel: "OFF", } LevelValue = map[string]Level{ "DEBUG": DebugLevel, "INFO": InfoLevel, "WARN": WarnLevel, "ERROR": ErrorLevel, "OFF": OffLevel, } )
Functions ¶
Types ¶
type Factory ¶
type Factory interface { // Logger returns a Logger by name, which may be cached. // It should never return nil. Logger(name string) Logger }
Factory is a Factory that produces Logger by name.
func GetFactory ¶
func GetFactory() Factory
GetFactory returns the registered Factory. It should never return nil. By default, a nop Logger Factory will be returned.
For any production projects, a vendor provided Factory should be registered first via SwapFactory before first calling GetFactory
func NewNopLoggerFactory ¶
func NewNopLoggerFactory() Factory
NewNopLoggerFactory returns a Factory that create Loggers that print nothing and enabled none Levels.
func SwapFactory ¶
SwapFactory registers new Factory, and returns the origin Factory.
For any production projects, a vendor provided Factory should be registered first via SwapFactory before first calling GetFactory
type Field ¶
type Field interface { // Key is field key. Key() string // Type is field type. Type() FieldType // Value is field value. Value() any }
Field is logging field.
func Boolp ¶
Boolp creates a Field of BoolType value if value is not nil, or a Field of UnknownType value if value is nil.
func Complex128 ¶
func Complex128(key string, value complex128) Field
Complex128 creates a Field of Complex128Type value.
func Complex128p ¶
func Complex128p(key string, value *complex128) Field
Complex128p creates a Field of Complex128Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Complex64p ¶
Complex64p creates a Field of Complex64Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Durationp ¶
Durationp creates a Field of DurationType value if value is not nil, or a Field of UnknownType value if value is nil.
func Float32p ¶
Float32p creates a Field of Float32Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Float64p ¶
Float64p creates a Field of Float64Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Int16p ¶
Int16p creates a Field of Int16Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Int32p ¶
Int32p creates a Field of Int32Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Int64p ¶
Int64p creates a Field of Int64Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Int8p ¶
Int8p creates a Field of Int8Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Intp ¶
Intp creates a Field of Int64Type value if value is not nil, or a Field of UnknownType value if value is nil.
func NamedError ¶
NamedError create a Field of ErrorType value.
func StackSkip ¶
StackSkip create a Field that captures stacktrace of the current goroutine, skipping the given number of frames from the top of the stacktrace.
func Stringp ¶
Stringp creates a Field of StringType value if value is not nil, or a Field of UnknownType value if value is nil.
func Timep ¶
Timep creates a Field of TimeType value if value is not nil, or a Field of UnknownType value if value is nil.
func Uint16p ¶
Uint16p creates a Field of Uint16Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Uint32p ¶
Uint32p creates a Field of Uint32Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Uint64p ¶
Uint64p creates a Field of Uint64Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Uint8p ¶
Uint8p creates a Field of Uint8Type value if value is not nil, or a Field of UnknownType value if value is nil.
func Uintp ¶
Uintp creates a Field of Uint64Type value if value is not nil, or a Field of UnknownType value if value is nil.
type FieldType ¶
type FieldType uint8
const ( // UnknownType is the default field type. UnknownType FieldType = iota // BinaryType indicates that the field carries an opaque binary blob. BinaryType // BoolType indicates that the field carries a bool. BoolType // Complex128Type indicates that the field carries a complex128. Complex128Type // Complex64Type indicates that the field carries a complex128. Complex64Type // DurationType indicates that the field carries a time.Duration. DurationType // Float64Type indicates that the field carries a float64. Float64Type // Float32Type indicates that the field carries a float32. Float32Type // Int64Type indicates that the field carries an int64. Int64Type // Int32Type indicates that the field carries an int32. Int32Type // Int16Type indicates that the field carries an int16. Int16Type // Int8Type indicates that the field carries an int8. Int8Type // StringType indicates that the field carries a string. StringType // TimeType indicates that the field carries a time.Time. TimeType // Uint64Type indicates that the field carries an uint64. Uint64Type // Uint32Type indicates that the field carries an uint32. Uint32Type // Uint16Type indicates that the field carries an uint16. Uint16Type // Uint8Type indicates that the field carries an uint8. Uint8Type // UintptrType indicates that the field carries an uintptr. UintptrType // StringerType indicates that the field carries a fmt.Stringer. StringerType // ErrorType indicates that the field carries an error. ErrorType // StackType indicates that the field captures stacktrace of the current goroutine. StackType )
type Level ¶
type Level int32
Level is a log level.
func (Level) Enabled ¶
Enabled Each concrete Level value implements a static LevelEnabler which returns true for itself and all higher logging levels, except OffLevel. For example WarnLevel.Enabled() will return true for WarnLevel and ErrorLevel but return false for InfoLevel and DebugLevel, and OffLevel.
func (Level) MarshalYAML ¶
func (*Level) UnmarshalYAML ¶
type LevelEnabler ¶
LevelEnabler decides whether a given logging level is enabled when logging a message.
type Logger ¶
type Logger interface { // LevelEnabler enforce a Logger provide a Enabled method. LevelEnabler // Debug outputs a log at DebugLevel if the Logger enabled DebugLevel. // // The parameters would be used to forming the log msg field // via formatting like the Print method does. // // If formatting is expensive, you'd better call Enabled method before do that. Debug(v ...any) // Debugln outputs a log at DebugLevel if the Logger enabled DebugLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Println method does but without an ending new line. // // If formatting is expensive, you'd better call Enabled method before do that. Debugln(v ...any) // Debugf outputs a log at DebugLevel if the Logger enabled DebugLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Printf method does. // // If formatting is expensive, you'd better call Enabled method before do that. Debugf(format string, v ...any) // Debugw outputs a log at DebugLevel if the Logger enabled DebugLevel. // // This method allow you log extra Fields to output. // // For fields with same name, usually, the later one override the former and builtin ones. // But a vendor may change this behavior by merge them. // Read the references of the vendor you chose about that. // // If you want format you msg field, do it before you call this method. // If formatting is expensive, you'd better call Enabled method before do that. Debugw(message string, field ...Field) // Info outputs a log at InfoLevel if the Logger enabled InfoLevel. // // The parameters would be used to forming the log msg field // via formatting like the Print method does. // // If formatting is expensive, you'd better call Enabled method before do that. Info(v ...any) // Infoln outputs a log at InfoLevel if the Logger enabled InfoLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Println method does but without an ending new line. // // If formatting is expensive, you'd better call Enabled method before do that. Infoln(v ...any) // Infof outputs a log at InfoLevel if the Logger enabled InfoLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Printf method does. // // If formatting is expensive, you'd better call Enabled method before do that. Infof(format string, v ...any) // Infow outputs a log at InfoLevel if the Logger enabled InfoLevel. // // This method allow you log extra Fields to output. // // For fields with same name, usually, the later one override the former and builtin ones. // But a vendor may change this behavior by merge them. // Read the references of the vendor you chose about that. // // If you want format you msg field, do it before you call this method. // If formatting is expensive, you'd better call Enabled method before do that. Infow(message string, field ...Field) // Warn outputs a log at WarnLevel if the Logger enabled WarnLevel. // // The parameters would be used to forming the log msg field // via formatting like the Print method does. // // If formatting is expensive, you'd better call Enabled method before do that. Warn(v ...any) // Warnln outputs a log at WarnLevel if the Logger enabled WarnLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Println method does but without an ending new line. // // If formatting is expensive, you'd better call Enabled method before do that. Warnln(v ...any) // Warnf outputs a log at WarnLevel if the Logger enabled WarnLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Printf method does. // // If formatting is expensive, you'd better call Enabled method before do that. Warnf(format string, v ...any) // Warnw outputs a log at WarnLevel if the Logger enabled WarnLevel. // // This method allow you log extra Fields to output. // // For fields with same name, usually, the later one override the former and builtin ones. // But a vendor may change this behavior by merge them. // Read the references of the vendor you chose about that. // // If you want format you msg field, do it before you call this method. // If formatting is expensive, you'd better call Enabled method before do that. Warnw(message string, field ...Field) // Error outputs a log at ErrorLevel if the Logger enabled ErrorLevel. // // The parameters would be used to forming the log msg field // via formatting like the Print method does. // // If formatting is expensive, you'd better call Enabled method before do that. Error(v ...any) // Errorln outputs a log at ErrorLevel if the Logger enabled ErrorLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Println method does but without an ending new line. // // If formatting is expensive, you'd better call Enabled method before do that. Errorln(v ...any) // Errorf outputs a log at ErrorLevel if the Logger enabled ErrorLevel. // // The parameters would be used to forming the log msg field // via formatting like the fmt.Printf method does. // // If formatting is expensive, you'd better call Enabled method before do that. Errorf(format string, v ...any) // Errorw outputs a log at ErrorLevel if the Logger enabled ErrorLevel. // // This method allow you log extra Fields to output. // // For fields with same name, usually, the later one override the former and builtin ones. // But a vendor may change this behavior by merge them. // Read the references of the vendor you chose about that. // // If you want format you msg field, do it before you call this method. // If formatting is expensive, you'd better call Enabled method before do that. Errorw(message string, field ...Field) // WithField returns a new Logger which wrap extra Fields, including fields of current Logger. // This method should never return nil. // // For fields with same name, usually, the later one override the former and builtin ones. // But a vendor may change this behavior by merge them. // Read the references of the vendor you chose about that. WithField(field ...Field) Logger }
Logger is logger interface.