Documentation ¶
Index ¶
- Constants
- Variables
- func AppendBool(b *Buffer, n bool)
- func AppendFloat32(b *Buffer, n float32)
- func AppendFloat64(b *Buffer, n float64)
- func AppendInt(b *Buffer, n int64)
- func AppendUint(b *Buffer, n uint64)
- func DefaultErrorEncoder(key string, err error, enc FieldEncoder)
- func DefaultLevelEncoder(lvl Level, m TypeEncoder)
- func EscapeByteString(buf *Buffer, s []byte) error
- func EscapeString(buf *Buffer, s string) error
- func FloatSecondsDurationEncoder(d time.Duration, e TypeEncoder)
- func FullCallerEncoder(c EntryCaller, m TypeEncoder)
- func NanoDurationEncoder(d time.Duration, e TypeEncoder)
- func NewContext(parent context.Context, logger *Logger) context.Context
- func RFC3339NanoTimeEncoder(t time.Time, e TypeEncoder)
- func RFC3339TimeEncoder(t time.Time, e TypeEncoder)
- func ShortCallerEncoder(c EntryCaller, m TypeEncoder)
- func StringDurationEncoder(d time.Duration, m TypeEncoder)
- func UnixNanoTimeEncoder(t time.Time, e TypeEncoder)
- func UpperCaseLevelEncoder(lvl Level, m TypeEncoder)
- type Appender
- type ArrayEncoder
- type Buffer
- func (b *Buffer) AppendByte(data byte)
- func (b *Buffer) AppendBytes(data []byte)
- func (b *Buffer) AppendString(data string)
- func (b *Buffer) Back() byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) EnsureSize(s int) []byte
- func (b *Buffer) ExtendBytes(s int) []byte
- func (b *Buffer) Len() int
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) Write(p []byte) (n int, err error)
- type Cache
- type CallerEncoder
- type ChannelWriterCloseFunc
- type ChannelWriterConfig
- type DurationEncoder
- type Encoder
- type Entry
- type EntryCaller
- type EntryWriter
- type ErrorEncoder
- type ErrorEncoderConfig
- type Field
- func Any(k string, v interface{}) Field
- func Array(k string, v ArrayEncoder) Field
- func Bool(k string, v bool) Field
- func Bools(k string, v []bool) Field
- func Bytes(k string, v []byte) Field
- func ConstBools(k string, v []bool) Field
- func ConstBytes(k string, v []byte) Field
- func ConstDurations(k string, v []time.Duration) Field
- func ConstFloats32(k string, v []float32) Field
- func ConstFloats64(k string, v []float64) Field
- func ConstFormatter(k string, verb string, v interface{}) Field
- func ConstFormatterV(k string, v interface{}) Field
- func ConstInts(k string, v []int) Field
- func ConstInts16(k string, v []int16) Field
- func ConstInts32(k string, v []int32) Field
- func ConstInts64(k string, v []int64) Field
- func ConstInts8(k string, v []int8) Field
- func ConstStringer(k string, v fmt.Stringer) Field
- func ConstUints(k string, v []uint) Field
- func ConstUints16(k string, v []uint16) Field
- func ConstUints32(k string, v []uint32) Field
- func ConstUints64(k string, v []uint64) Field
- func ConstUints8(k string, v []uint8) Field
- func Duration(k string, v time.Duration) Field
- func Durations(k string, v []time.Duration) Field
- func Error(v error) Field
- func Float32(k string, v float32) Field
- func Float64(k string, v float64) Field
- func Floats32(k string, v []float32) Field
- func Floats64(k string, v []float64) Field
- func Formatter(k string, verb string, v interface{}) Field
- func FormatterV(k string, v interface{}) Field
- func Int(k string, v int) Field
- func Int16(k string, v int16) Field
- func Int32(k string, v int32) Field
- func Int64(k string, v int64) Field
- func Int8(k string, v int8) Field
- func Ints(k string, v []int) Field
- func Ints16(k string, v []int16) Field
- func Ints32(k string, v []int32) Field
- func Ints64(k string, v []int64) Field
- func Ints8(k string, v []int8) Field
- func NamedError(k string, v error) Field
- func Object(k string, v ObjectEncoder) Field
- func String(k string, v string) Field
- func Stringer(k string, v fmt.Stringer) Field
- func Strings(k string, v []string) Field
- func Time(k string, v time.Time) Field
- func Uint(k string, v uint) Field
- func Uint16(k string, v uint16) Field
- func Uint32(k string, v uint32) Field
- func Uint64(k string, v uint64) Field
- func Uint8(k string, v uint8) Field
- func Uints(k string, v []uint) Field
- func Uints16(k string, v []uint16) Field
- func Uints32(k string, v []uint32) Field
- func Uints64(k string, v []uint64) Field
- func Uints8(k string, v []uint8) Field
- type FieldEncoder
- type FieldType
- type JSONEncoderConfig
- type Level
- type LevelChecker
- type LevelCheckerGetter
- type LevelCheckerGetterFunc
- type LevelEncoder
- type LogFunc
- type Logger
- func (l *Logger) AtLevel(lvl Level, fn func(LogFunc))
- func (l *Logger) Debug(text string, fs ...Field)
- func (l *Logger) Error(text string, fs ...Field)
- func (l *Logger) Info(text string, fs ...Field)
- func (l *Logger) Warn(text string, fs ...Field)
- func (l *Logger) With(fs ...Field) *Logger
- func (l *Logger) WithCaller() *Logger
- func (l *Logger) WithCallerSkip(skip int) *Logger
- func (l *Logger) WithLevel(level LevelCheckerGetter) *Logger
- func (l *Logger) WithName(n string) *Logger
- type MutableLevel
- type ObjectEncoder
- type Snapshotter
- type TimeEncoder
- type TypeEncoder
- type TypeEncoderFactory
Constants ¶
const ( DefaultFieldKeyLevel = "level" DefaultFieldKeyMsg = "msg" DefaultFieldKeyTime = "ts" DefaultFieldKeyName = "logger" DefaultFieldKeyCaller = "caller" )
Default field keys.
const (
PageSize = 4 * 1024
)
PageSize is the recommended buffer size.
Variables ¶
var NewChannelWriter = channelWriterGetter( func(cfg ChannelWriterConfig) (EntryWriter, ChannelWriterCloseFunc) { l := &channelWriter{} l.init(cfg.WithDefaults()) return l, ChannelWriterCloseFunc( func() { l.close() }) }, )
NewChannelWriter returns a new ChannelWriter with the given config.
var NewErrorEncoder = errorEncoderGetter( func(c ErrorEncoderConfig) ErrorEncoder { return func(key string, err error, enc FieldEncoder) { encodeError(key, err, enc, c.WithDefaults()) } }, )
NewErrorEncoder creates the new instance of the ErrorEncoder with the given ErrorEncoderConfig.
var NewJSONEncoder = jsonEncoderGetter( func(cfg JSONEncoderConfig) Encoder { return &jsonEncoder{cfg.WithDefaults(), NewCache(100), nil, 0} }, )
NewJSONEncoder creates the new instance of the JSON Encoder with the given JSONEncoderConfig.
var NewJSONTypeEncoderFactory = jsonTypeEncoderFactoryGetter( func(c JSONEncoderConfig) TypeEncoderFactory { return &jsonEncoder{c.WithDefaults(), nil, nil, 0} }, )
NewJSONTypeEncoderFactory creates the new instance of the JSON TypeEncoderFactory with the given JSONEncoderConfig.
Functions ¶
func AppendBool ¶
AppendBool appends "true" or "false", according to the given bool to the given Buffer.
func AppendFloat32 ¶
AppendFloat32 appends the string form of the given float32 to the given Buffer.
func AppendFloat64 ¶
AppendFloat64 appends the string form of the given float32 to the given Buffer.
func AppendInt ¶
AppendInt appends the string form in the base 10 of the given integer to the given Buffer.
func AppendUint ¶
AppendUint appends the string form in the base 10 of the given unsigned integer to the given Buffer.
func DefaultErrorEncoder ¶
func DefaultErrorEncoder(key string, err error, enc FieldEncoder)
DefaultErrorEncoder encodes the given error as a set of fields.
A mandatory field with the given key and an optional field with the full verbose error message.
func DefaultLevelEncoder ¶
func DefaultLevelEncoder(lvl Level, m TypeEncoder)
DefaultLevelEncoder implements LevelEncoder by calling Level itself.
func EscapeByteString ¶
EscapeByteString processes a single escape sequence to the given Buffer.
func EscapeString ¶
EscapeString processes a single escape sequence to the given Buffer.
func FloatSecondsDurationEncoder ¶ added in v1.0.1
func FloatSecondsDurationEncoder(d time.Duration, e TypeEncoder)
FloatSecondsDurationEncoder encodes the given Duration to a floating-point number of seconds elapsed.
func FullCallerEncoder ¶
func FullCallerEncoder(c EntryCaller, m TypeEncoder)
FullCallerEncoder encodes the given EntryCaller using a full file path.
func NanoDurationEncoder ¶
func NanoDurationEncoder(d time.Duration, e TypeEncoder)
NanoDurationEncoder encodes the given Duration as a number of nanoseconds.
func NewContext ¶
NewContext returns a new Context with the given Logger inside it.
func RFC3339NanoTimeEncoder ¶
func RFC3339NanoTimeEncoder(t time.Time, e TypeEncoder)
RFC3339NanoTimeEncoder encodes the given Time as a string using RFC3339Nano layout.
func RFC3339TimeEncoder ¶
func RFC3339TimeEncoder(t time.Time, e TypeEncoder)
RFC3339TimeEncoder encodes the given Time as a string using RFC3339 layout.
func ShortCallerEncoder ¶
func ShortCallerEncoder(c EntryCaller, m TypeEncoder)
ShortCallerEncoder encodes the given EntryCaller using it's FileWithPackage function.
func StringDurationEncoder ¶
func StringDurationEncoder(d time.Duration, m TypeEncoder)
StringDurationEncoder encodes the given Duration as a string using Stringer interface.
func UnixNanoTimeEncoder ¶
func UnixNanoTimeEncoder(t time.Time, e TypeEncoder)
UnixNanoTimeEncoder encodes the given Time as a Unix time, the number of of nanoseconds elapsed since January 1, 1970 UTC.
func UpperCaseLevelEncoder ¶
func UpperCaseLevelEncoder(lvl Level, m TypeEncoder)
UpperCaseLevelEncoder implements LevelEncoder by calling Level itself.
Types ¶
type Appender ¶
type Appender interface { // Append logs the Entry in Appender specific way. Append(Entry) error // Flush writes uncommitted changes to the underlying buffer of Writer. Flush() error // Sync writes uncommitted changes to the stable storage. For files this // means flushing the file system's in-memory copy of recently written // data to disk. Sync() error }
Appender is the interface for your own strategies for outputting log entries.
func NewDiscardAppender ¶
func NewDiscardAppender() Appender
NewDiscardAppender returns a new Appender that does nothing.
type ArrayEncoder ¶
type ArrayEncoder interface {
EncodeLogfArray(TypeEncoder) error
}
ArrayEncoder defines the interface to create your own array logger.
Example:
type stringArray []string
func (o stringArray) EncodeLogfArray(e TypeEncoder) error { for i := range o { e.EncodeTypeString(o[i]) } return nil }
type Buffer ¶
type Buffer struct {
Data []byte
}
Buffer is a helping wrapper for byte slice.
func NewBuffer ¶
func NewBuffer() *Buffer
NewBuffer creates the new instance of Buffer with default capacity.
func NewBufferWithCapacity ¶
NewBufferWithCapacity creates the new instance of Buffer with the given capacity.
func (*Buffer) AppendByte ¶
AppendByte appends a single byte to the Buffer.
func (*Buffer) AppendBytes ¶
AppendBytes appends a byte slice to the Buffer.
func (*Buffer) AppendString ¶
AppendString appends a string to the Buffer.
func (*Buffer) Back ¶
Back returns the last byte of the underlying byte slice. A caller is in charge of checking that the Buffer is not empty.
func (*Buffer) EnsureSize ¶
EnsureSize ensures that the Buffer is able to append 's' bytes without a further realloc.
func (*Buffer) ExtendBytes ¶
ExtendBytes extends the Buffer with the given size and returns a slice tp extended part of the Buffer.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the simple implementation of LRU cache. The Cache is not goroutine safe.
type CallerEncoder ¶
type CallerEncoder func(EntryCaller, TypeEncoder)
CallerEncoder is the function type to encode the given EntryCaller.
type ChannelWriterCloseFunc ¶
type ChannelWriterCloseFunc func()
ChannelWriterCloseFunc allows to close channel writer.
type ChannelWriterConfig ¶
type ChannelWriterConfig struct { // Capacity specifies the underlying channel capacity. Capacity int // Appender specified the basic Appender for all Entries. // // Default Appender is WriterAppender with JSON Encoder. Appender Appender // ErrorAppender specifies the Appender for errors returning by basic // Appender. // // Default ErrorAppender does nothing. ErrorAppender Appender // EnableSyncOnError specifies whether Appender.Sync should be called // for messages with LevelError or not. // // Default value is false. EnableSyncOnError bool }
ChannelWriterConfig allows to configure ChannelWriter.
func (ChannelWriterConfig) WithDefaults ¶
func (c ChannelWriterConfig) WithDefaults() ChannelWriterConfig
WithDefaults returns the new config in which all uninitialized fields are filled with their default values.
type DurationEncoder ¶
type DurationEncoder func(time.Duration, TypeEncoder)
DurationEncoder is the function type to encode the given Duration.
type Encoder ¶
Encoder defines the interface to create your own log format.
In case of error, Encoder must remove bytes related to the given Entry from the Buffer.
type Entry ¶
type Entry struct { // LoggerID specifies a unique logger identifies. LoggerID int32 // LoggerName specifies a non-unique name of a logger. // Can be empty. LoggerName string // DeriviedFields specifies logger data fields including fields of // logger parents. The earliest fields (parent's fields) go first. DerivedFields []Field // Fields specifies data fields of a log message. Fields []Field // Level specifies a severity level of a log message. Level Level // Time specifies a timestamp of a log message. Time time.Time // Text specifies a text message of a log message. Text string // Caller specifies file:line info about an Entry's caller. Caller EntryCaller }
Entry holds a single log message and fields.
type EntryCaller ¶
EntryCaller holds values returned by runtime.Caller.
func NewEntryCaller ¶
func NewEntryCaller(skip int) EntryCaller
NewEntryCaller creates an instance of EntryCaller with the given number of frames to skip.
func (EntryCaller) FileWithPackage ¶
func (c EntryCaller) FileWithPackage() string
FileWithPackage cuts a package name and a file name from EntryCaller.File.
type EntryWriter ¶
type EntryWriter interface {
WriteEntry(Entry)
}
EntryWriter is the interface that should do real logging stuff.
func NewUnbufferedEntryWriter ¶ added in v1.0.1
func NewUnbufferedEntryWriter(appender Appender) EntryWriter
NewUnbufferedEntryWriter returns an implementation of EntryWriter which puts entries directly to the appender immediately and synchronously.
type ErrorEncoder ¶
type ErrorEncoder func(string, error, FieldEncoder)
ErrorEncoder is the function type to encode the given error.
type ErrorEncoderConfig ¶ added in v1.0.1
ErrorEncoderConfig allows to configure ErrorEncoder.
func (ErrorEncoderConfig) WithDefaults ¶ added in v1.0.1
func (c ErrorEncoderConfig) WithDefaults() ErrorEncoderConfig
WithDefaults returns the new config in which all uninitialized fields are filled with their default values.
type Field ¶
Field hold data of a specific field.
func Any ¶
Any returns a new Filed with the given key and value of any type. Is tries to choose the best way to represent key-value pair as a Field.
Note that Any is not possible to choose ConstX methods. Use specific Field methods for better performance.
func Array ¶
func Array(k string, v ArrayEncoder) Field
Array returns a new Field with the given key and ArrayEncoder.
func ConstBools ¶
ConstBools returns a new Field with the given key and slice of bools.
Call ConstBools if your array is const. It has significantly less impact on the calling goroutine.
func ConstBytes ¶
ConstBytes returns a new Field with the given key and slice of bytes.
Call ConstBytes if your array is const. It has significantly less impact on the calling goroutine.
func ConstDurations ¶
ConstDurations returns a new Field with the given key and slice of time.Duration.
Call ConstDurations if your array is const. It has significantly less impact on the calling goroutine.
func ConstFloats32 ¶
ConstFloats32 returns a new Field with the given key and slice of 32-bit floats.
Call ConstFloats32 if your array is const. It has significantly less impact on the calling goroutine.
func ConstFloats64 ¶
ConstFloats64 returns a new Field with the given key and slice of 64-bit floats.
Call ConstFloats64 if your array is const. It has significantly less impact on the calling goroutine.
func ConstFormatter ¶
ConstFormatter returns a new Field with the given key, verb and interface to format.
Call ConstFormatter if your object is const. It has significantly less impact on the calling goroutine.
func ConstFormatterV ¶
ConstFormatterV returns a new Field with the given key and interface to format. It uses the predefined verb "%#v" (a Go-syntax representation of the value).
Call ConstFormatterV if your object is const. It has significantly less impact on the calling goroutine.
func ConstInts ¶
ConstInts returns a new Field with the given key and slice of ints.
Call ConstInts if your array is const. It has significantly less impact on the calling goroutine.
func ConstInts16 ¶
ConstInts16 returns a new Field with the given key and slice of 16-bit ints.
Call ConstInts16 if your array is const. It has significantly less impact on the calling goroutine.
func ConstInts32 ¶
ConstInts32 returns a new Field with the given key and slice of 32-bit ints.
Call ConstInts32 if your array is const. It has significantly less impact on the calling goroutine.
func ConstInts64 ¶
ConstInts64 returns a new Field with the given key and slice of 64-bit ints.
Call ConstInts64 if your array is const. It has significantly less impact on the calling goroutine.
func ConstInts8 ¶
ConstInts8 returns a new Field with the given key and slice of 8-bit ints.
Call ConstInts8 if your array is const. It has significantly less impact on the calling goroutine.
func ConstStringer ¶
ConstStringer returns a new Field with the given key and Stringer. Call ConstStringer if your object is const. It has significantly less impact on the calling goroutine.
func ConstUints ¶
ConstUints returns a new Field with the given key and slice of uints.
Call ConstUints if your array is const. It has significantly less impact on the calling goroutine.
func ConstUints16 ¶
ConstUints16 returns a new Field with the given key and slice of 16-bit uints.
Call ConstUints16 if your array is const. It has significantly less impact on the calling goroutine.
func ConstUints32 ¶
ConstUints32 returns a new Field with the given key and slice of 32-bit uints.
Call ConstUints32 if your array is const. It has significantly less impact on the calling goroutine.
func ConstUints64 ¶
ConstUints64 returns a new Field with the given key and slice of 64-bit uints.
Call ConstUints64 if your array is const. It has significantly less impact on the calling goroutine.
func ConstUints8 ¶
ConstUints8 returns a new Field with the given key and slice of 8-bit uints.
Call ConstUints8 if your array is const. It has significantly less impact on the calling goroutine.
func FormatterV ¶
FormatterV returns a new Field with the given key and interface to format. It uses the predefined verb "%#v" (a Go-syntax representation of the value).
func NamedError ¶
NamedError returns a new Field with the given key and error.
func Object ¶
func Object(k string, v ObjectEncoder) Field
Object returns a new Field with the given key and ObjectEncoder.
func (Field) Accept ¶
func (fd Field) Accept(v FieldEncoder)
Accept interprets Field data according to FieldType and calls appropriate FieldEncoder function.
type FieldEncoder ¶
type FieldEncoder interface { EncodeFieldAny(string, interface{}) EncodeFieldBool(string, bool) EncodeFieldInt64(string, int64) EncodeFieldInt32(string, int32) EncodeFieldInt16(string, int16) EncodeFieldInt8(string, int8) EncodeFieldUint64(string, uint64) EncodeFieldUint32(string, uint32) EncodeFieldUint16(string, uint16) EncodeFieldUint8(string, uint8) EncodeFieldFloat64(string, float64) EncodeFieldFloat32(string, float32) EncodeFieldDuration(string, time.Duration) EncodeFieldError(string, error) EncodeFieldTime(string, time.Time) EncodeFieldString(string, string) EncodeFieldStrings(string, []string) EncodeFieldBytes(string, []byte) EncodeFieldBools(string, []bool) EncodeFieldInts64(string, []int64) EncodeFieldInts32(string, []int32) EncodeFieldInts16(string, []int16) EncodeFieldInts8(string, []int8) EncodeFieldUints64(string, []uint64) EncodeFieldUints32(string, []uint32) EncodeFieldUints16(string, []uint16) EncodeFieldUints8(string, []uint8) EncodeFieldFloats64(string, []float64) EncodeFieldFloats32(string, []float32) EncodeFieldDurations(string, []time.Duration) EncodeFieldArray(string, ArrayEncoder) EncodeFieldObject(string, ObjectEncoder) }
FieldEncoder defines the interface that allows to encode basic types with field names. Encoder companion.
type FieldType ¶
type FieldType byte
FieldType specifies how to handle Field data.
const ( FieldTypeUnknown FieldType = iota FieldTypeAny FieldTypeBool FieldTypeInt64 FieldTypeInt32 FieldTypeInt16 FieldTypeInt8 FieldTypeUint64 FieldTypeUint32 FieldTypeUint16 FieldTypeUint8 FieldTypeFloat64 FieldTypeFloat32 FieldTypeDuration FieldTypeError FieldTypeTime FieldTypeBytes FieldTypeBytesToString FieldTypeBytesToBools FieldTypeBytesToInts64 FieldTypeBytesToInts32 FieldTypeBytesToInts16 FieldTypeBytesToInts8 FieldTypeBytesToUints64 FieldTypeBytesToUints32 FieldTypeBytesToUints16 FieldTypeBytesToUints8 FieldTypeBytesToFloats64 FieldTypeBytesToFloats32 FieldTypeBytesToDurations FieldTypeArray FieldTypeObject FieldTypeStringer FieldTypeFormatter )
Set of FileType values.
const ( FieldTypeRawMask FieldType = 1<<7 + iota FieldTypeRawBytes FieldTypeRawBytesToBools FieldTypeRawBytesToInts64 FieldTypeRawBytesToInts32 FieldTypeRawBytesToInts16 FieldTypeRawBytesToInts8 FieldTypeRawBytesToUints64 FieldTypeRawBytesToUints32 FieldTypeRawBytesToUints16 FieldTypeRawBytesToUints8 FieldTypeRawBytesToFloats64 FieldTypeRawBytesToFloats32 FieldTypeRawBytesToDurations )
Special cases that are processed during snapshoting phase.
type JSONEncoderConfig ¶
type JSONEncoderConfig struct { FieldKeyMsg string FieldKeyTime string FieldKeyLevel string FieldKeyName string FieldKeyCaller string DisableFieldMsg bool DisableFieldTime bool DisableFieldLevel bool DisableFieldName bool DisableFieldCaller bool EncodeTime TimeEncoder EncodeDuration DurationEncoder EncodeError ErrorEncoder EncodeLevel LevelEncoder EncodeCaller CallerEncoder }
JSONEncoderConfig allows to configure journal JSON Encoder.
func (JSONEncoderConfig) WithDefaults ¶
func (c JSONEncoderConfig) WithDefaults() JSONEncoderConfig
WithDefaults returns the new config in which all uninitialized fields are filled with their default values.
type Level ¶
type Level int8
Level defines severity level of a log message.
const ( // LevelError allows to log errors only. LevelError Level = iota // LevelWarn allows to log errors and warnings. LevelWarn // LevelInfo is the default logging level. Allows to log errors, warnings and infos. LevelInfo // LevelDebug allows to log messages with all severity levels. LevelDebug )
Severity levels.
func LevelFromString ¶
LevelFromString creates the new Level with the given string.
func (Level) Checker ¶
func (l Level) Checker() LevelChecker
Checker is the common way to get LevelChecker. Use it with every custom implementation of Level.
func (Level) LevelChecker ¶
func (l Level) LevelChecker() LevelChecker
LevelChecker implements LevelCheckerGetter.
func (Level) MarshalText ¶ added in v1.2.0
MarshalText marshals the Level to text.
func (Level) String ¶
String implements fmt.Stringer. String returns a lower-case string representation of the Level.
func (*Level) UnmarshalText ¶ added in v1.2.0
UnmarshalText unmarshals the Level from text.
func (Level) UpperCaseString ¶
UpperCaseString returns an upper-case string representation of the Level.
type LevelChecker ¶
LevelChecker abstracts level checking process.
type LevelCheckerGetter ¶
type LevelCheckerGetter interface {
LevelChecker() LevelChecker
}
LevelCheckerGetter allows the implementor to act like a common Level checker for the Logger.
type LevelCheckerGetterFunc ¶
type LevelCheckerGetterFunc func() LevelChecker
LevelCheckerGetterFunc defines a function that returns LevelChecker.
func (LevelCheckerGetterFunc) LevelChecker ¶
func (fn LevelCheckerGetterFunc) LevelChecker() LevelChecker
LevelChecker implements LevelCheckerGetter interface.
type LevelEncoder ¶
type LevelEncoder func(Level, TypeEncoder)
LevelEncoder is the function type to encode Level.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the fast, asynchronous, structured logger.
The Logger wraps EntryWriter to check logging level and provide a bit of syntactic sugar.
func DisabledLogger ¶ added in v1.0.1
func DisabledLogger() *Logger
DisabledLogger returns a default instance of a Logger that logs nothing as fast as possible.
func FromContext ¶
FromContext returns the Logger associated with this context or nil if no value is associated. Successive calls to FromContext returns the same result.
func NewDisabledLogger ¶
func NewDisabledLogger() *Logger
NewDisabledLogger return a new Logger that logs nothing as fast as possible.
func NewLogger ¶
func NewLogger(level LevelCheckerGetter, w EntryWriter) *Logger
NewLogger returns a new Logger with a given Level and EntryWriter.
func (*Logger) AtLevel ¶
AtLevel calls the given fn if logging a message at the specified level is enabled, passing a LogFunc with the bound level.
func (*Logger) Debug ¶
Debug logs a debug message with the given text, optional fields and fields passed to the Logger using With function.
func (*Logger) Error ¶
Error logs an error message with the given text, optional fields and fields passed to the Logger using With function.
func (*Logger) Info ¶
Info logs an info message with the given text, optional fields and fields passed to the Logger using With function.
func (*Logger) Warn ¶
Warn logs a warning message with the given text, optional fields and fields passed to the Logger using With function.
func (*Logger) WithCaller ¶
WithCaller returns a new Logger that adds a special annotation parameters to each logging message, such as the filename and line number of a caller.
func (*Logger) WithCallerSkip ¶
WithCallerSkip returns a new Logger with increased number of skipped frames. It's usable to build a custom wrapper for the Logger.
func (*Logger) WithLevel ¶ added in v1.4.0
func (l *Logger) WithLevel(level LevelCheckerGetter) *Logger
WithLevel returns a new logger with the given additional level checker.
type MutableLevel ¶
type MutableLevel struct {
// contains filtered or unexported fields
}
MutableLevel allows to switch the logging level atomically.
The logger does not allow to change logging level in runtime by itself.
func NewMutableLevel ¶
func NewMutableLevel(l Level) *MutableLevel
NewMutableLevel creates an instance of MutableLevel with the given starting level.
func (*MutableLevel) Checker ¶
func (l *MutableLevel) Checker() LevelChecker
Checker is common way to get LevelChecker. Use it with every custom implementation of Level.
func (*MutableLevel) Level ¶
func (l *MutableLevel) Level() Level
Level returns the current logging level.
func (*MutableLevel) LevelChecker ¶
func (l *MutableLevel) LevelChecker() LevelChecker
LevelChecker implements LevelCheckerGetter.
func (*MutableLevel) Set ¶
func (l *MutableLevel) Set(o Level)
Set switches the current logging level to the given one.
type ObjectEncoder ¶
type ObjectEncoder interface {
EncodeLogfObject(FieldEncoder) error
}
ObjectEncoder defines the interface to create your own object logger.
Example:
type user struct { Username string Password string } func (u user) EncodeLogfObject(e FieldEncoder) error { e.EncodeFieldString("username", u.Username) e.EncodeFieldString("password", u.Password) return nil }
type Snapshotter ¶
type Snapshotter interface {
TakeSnapshot() interface{}
}
Snapshotter is the interface that allows to do a custom copy of a logging object. If the object type implements TaskSnapshot function it will be called during the logging procedure in a caller's goroutine.
type TimeEncoder ¶
type TimeEncoder func(time.Time, TypeEncoder)
TimeEncoder is the function type to encode the given Time.
func LayoutTimeEncoder ¶
func LayoutTimeEncoder(layout string) TimeEncoder
LayoutTimeEncoder encodes the given Time as a string using custom layout.
type TypeEncoder ¶
type TypeEncoder interface { EncodeTypeAny(interface{}) EncodeTypeBool(bool) EncodeTypeInt64(int64) EncodeTypeInt32(int32) EncodeTypeInt16(int16) EncodeTypeInt8(int8) EncodeTypeUint64(uint64) EncodeTypeUint32(uint32) EncodeTypeUint16(uint16) EncodeTypeUint8(uint8) EncodeTypeFloat64(float64) EncodeTypeFloat32(float32) EncodeTypeDuration(time.Duration) EncodeTypeTime(time.Time) EncodeTypeString(string) EncodeTypeStrings([]string) EncodeTypeBytes([]byte) EncodeTypeBools([]bool) EncodeTypeInts64([]int64) EncodeTypeInts32([]int32) EncodeTypeInts16([]int16) EncodeTypeInts8([]int8) EncodeTypeUints64([]uint64) EncodeTypeUints32([]uint32) EncodeTypeUints16([]uint16) EncodeTypeUints8([]uint8) EncodeTypeFloats64([]float64) EncodeTypeFloats32([]float32) EncodeTypeDurations([]time.Duration) EncodeTypeArray(ArrayEncoder) EncodeTypeObject(ObjectEncoder) EncodeTypeUnsafeBytes(unsafe.Pointer) }
TypeEncoder defines the interface that allows to encode basic types. Encoder companion.
type TypeEncoderFactory ¶
type TypeEncoderFactory interface {
TypeEncoder(*Buffer) TypeEncoder
}
TypeEncoderFactory defines the interface that allows to reuse Encoder internal-defined TypeEncoder in other encoder.
E.g. logf json encoder implements TypeEncoderFactory allowing all other encoders to use json encoding functionality in some cases.