Documentation
¶
Index ¶
- type Context
- type Encoder
- func (e Encoder) Array(key string, fn func(Encoder))
- func (e Encoder) Bool(key string, value bool)
- func (e Encoder) BoolSlice(key string, values []bool)
- func (e Encoder) Bytes(key string, values []byte)
- func (e Encoder) Err(key string, value error)
- func (e Encoder) Float(key string, value float64)
- func (e Encoder) FloatSlice(key string, values []float64)
- func (e Encoder) Int(key string, value int)
- func (e Encoder) Int64(key string, value int64)
- func (e Encoder) Int64Slice(key string, values []int64)
- func (e Encoder) IntSlice(key string, values []int)
- func (e Encoder) Nil(key string)
- func (e Encoder) Object(key string, fn func(Encoder))
- func (e Encoder) RawString(key, value string)
- func (e Encoder) Release()
- func (e Encoder) String(key, value string)
- func (e Encoder) StringBytes(key string, value []byte)
- func (e Encoder) StringSlice(key string, values []string)
- func (e Encoder) Stringer(key string, value fmt.Stringer)
- func (e Encoder) Time(key string, value time.Time, layout string)
- func (e Encoder) Timestamp(key string, value time.Time)
- func (e Encoder) Uint64(key string, value uint64)
- func (e Encoder) Uint64Slice(key string, values []uint64)
- func (e Encoder) Value(key string, value interface{})
- type LogLevel
- type Logger
- func (l *Logger) Debug(message string, fields ...Context)
- func (l *Logger) Dump(v interface{})
- func (l *Logger) Error(err error, fields ...Context)
- func (l *Logger) Info(message string, fields ...Context)
- func (l *Logger) Panic(err error, fields ...Context)
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Sync() error
- type Options
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context func(Encoder)
Context represents the context in which the log was output.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is the type on which you encode all your context values.
func (Encoder) Array ¶
Array encases fn in an array
Example:
e.Array(key, func(enc medea.Encoder) { for _, v := range mySlice { enc.String("", v.Name) } })
func (Encoder) FloatSlice ¶
FloatSlice encodes values as an array of the contents.
func (Encoder) Int64Slice ¶
Int64Slice encodes values as an array of the contents.
func (Encoder) Object ¶
Object encases fn in an object
Example:
e.Object(key, func(enc medea.Encoder) { for k, v := range myMap { enc.String(k, v.Name) } })
func (Encoder) RawString ¶
RawString has no escaping at all, not even quotes for JSON. Use String in most cases (RawString is faster though).
func (Encoder) StringBytes ¶
StringBytes is similar to RawString(key, string(value)), but doesn't allocate.
func (Encoder) StringSlice ¶
StringSlice encodes values as an array of the contents.
func (Encoder) Uint64Slice ¶
Uint64Slice encodes values as an array of the contents.
type LogLevel ¶
type LogLevel int8
LogLevel represents a logging level. If a *Logger is at ErrorLevel, a log.Warn WILL NOT be output. If a *Logger is at InfoLevel, a log.Info WILL be output.
Basic recommendations:
fatal: wake the sysadmin up in the middle of the night panic: log them (deduplicated) to the devops slack/discord/teams channel error: periodically log their count to the dev channel, make them easily accessible info: periodically log their count to the dev channel debug: disabled in production
const ( // Error: problem happened. ErrorLevel LogLevel = iota - 1 // Informational: informational messages (lots of packets are dropping, system is slower than usual). InfoLevel // Debug: debug-level messages, should be disabled in production. DebugLevel // All levels enabled. All LogLevel = 127 // Disables the logger. Disabled LogLevel = -128 )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents the logger An empty value is INVALID.
func Default ¶
func Default() *Logger
Default returns a ready-to-use *Logger, writing on Stderr with Debug level.
func (*Logger) Debug ¶
Debug logs message (and fields) at DebugLevel, and honors BetterDebug
Do NOT log sensitive info, even in debug level.
func (*Logger) Dump ¶
func (l *Logger) Dump(v interface{})
Dump dumps the content of v with fmt.Printf("%+v", v) onto the debug stack (honoring BetterDebug).
func (*Logger) Error ¶
Error logs err at ErrorLevel
If err is nil, doesn't log, so you can log.Error(file.Close()) and it won't log if there is no error closing the file.
func (*Logger) Panic ¶
Panic logs err at ErrorLevel, and then panics with err
If err is nil, doesn't log nor panics.
You can use for application initialization, for example in config loading:
conf, err := loadConfig() log.Panic(err) // now conf is valid
type Options ¶
type Options struct { Target Target // Target on which to output the logs, defaults to Stderr Level LogLevel // LogLevel of the Logger, defaults to ErrorLevel LevelKey string // Key to use for logging LogLevel, defaults to "level" if empty NameKey string // Key to use for logging Name, defaults to "name" if empty CallerKey string // Key to use to print caller (file, line, function name), big perforance hit TimeKey string // Key to use for logging timestamp TimeFormat string // Format to use, uses a simple but fast UnixNano timestamp if empty Context Context // Static context to log alongside other fields OnError func(error) // Called when internal write error happened // When true, TimeFormat defaults to as RFC3339, and caller is always on for the Debug stack BetterDebug bool }
Options is the Logger options, passed to New() An empty *Key value means the corresponding context WILL NOT be output.
Directories
¶
Path | Synopsis |
---|---|
pkg
|
|
medea
Package medea implements fast and easy json serialization for all This library is optimized for 64-bit architectures and may not work on 32-bit
|
Package medea implements fast and easy json serialization for all This library is optimized for 64-bit architectures and may not work on 32-bit |