Documentation
¶
Overview ¶
Package log defines the logging facade
A logger is composed of a formatter that serialises the log structure into a text line, and a log printer that outputs the formatted log lines.
Index ¶
- type Ctx
- type Field
- func Base64(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Duration(key string, val time.Duration) Field
- func Error(err error) Field
- func Float64(key string, val float64) Field
- func Int(key string, val int) Field
- func Int64(key string, val int64) Field
- func Nest(key string, fields ...Field) Field
- func Object(key string, val interface{}) Field
- func Ptr(key string, val interface{}) Field
- func Skip() Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Time(key string, val time.Time) Field
- func Type(key string, val interface{}) Field
- func Uint(key string, val uint) Field
- func Uint64(key string, val uint64) Field
- func Uintptr(key string, val uintptr) Field
- type Formatter
- type Level
- type Logger
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
A Field is a marshaling operation used to add a key-value pair to a logger's context. Most fields are lazily marshaled, so it's inexpensive to add fields to disabled debug-level log statements.
func Base64 ¶
Base64 constructs a field that encodes the given value as a padded base64 string. The byte slice is converted to a base64 string eagerly.
func Duration ¶
Duration constructs a Field with the given key and value. It represents durations as an integer number of nanoseconds.
func Error ¶
Error constructs a Field that lazily stores err.Error() under the key "error". If passed a nil error, the field is a no-op.
func Float64 ¶
Float64 constructs a Field with the given key and value. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Int64 ¶
Int64 constructs a Field with the given key and value. Like ints, int64s are marshaled lazily.
func Object ¶
Object constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Object includes the error message in the final log output.
func Stringer ¶
Stringer constructs a Field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Time ¶
Time constructs a Field with the given key and value. It represents a time.Time as a floating-point number of seconds since epoch. Conversion to a float64 happens eagerly.
type Formatter ¶
type Formatter interface { // Format formats the given log line Format(ctx *Ctx, tag, msg string, fields ...Field) (string, error) }
Formatter converts a log line to a specific format, such as JSON
type Level ¶
type Level int
Level defines log severity
func ParseLevel ¶ added in v1.2.1
ParseLevel parses a string representation of a log level
type Logger ¶
type Logger interface { // Trace level logs are to follow the code executio step by step Trace(tag, msg string, fields ...Field) // Warning level logs are meant to draw attention above a certain threshold // e.g. wrong credentials, 404 status code returned, upstream node down Warning(tag, msg string, fields ...Field) // Error level logs need immediate attention // The 2AM rule applies here, which means that if you are on call, this log line will wake you up at 2AM // e.g. all critical upstream nodes are down, disk space is full Error(tag, msg string, fields ...Field) // With returns a child logger, and optionally add some context to that logger With(fields ...Field) Logger // AddCalldepth adds the given value to calldepth // Calldepth is the count of the number of // frames to skip when computing the file name and line number AddCalldepth(n int) Logger }
Logger is an interface for app loggers
Directories
¶
Path | Synopsis |
---|---|
json
Package json is a JSON log formatter.
|
Package json is a JSON log formatter. |
logf
Package logf is a human friendly log formatter.
|
Package logf is a human friendly log formatter. |
stdout
Package stdout prints log lines into the standard output.
|
Package stdout prints log lines into the standard output. |