Documentation
¶
Index ¶
- Variables
- func Crit(msg string, ctx ...interface{})
- func Debug(msg string, ctx ...interface{})
- func Error(msg string, ctx ...interface{})
- func Info(msg string, ctx ...interface{})
- func PrintOrigins(print bool)
- func Trace(msg string, ctx ...interface{})
- func Warn(msg string, ctx ...interface{})
- type Ctx
- type Format
- type GlogHandler
- type Handler
- type Lazy
- type Logger
- type Lvl
- type Record
- type RecordKeyNames
- type TerminalStringer
Constants ¶
This section is empty.
Variables ¶
var ( StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat()) StderrHandler = StreamHandler(os.Stderr, LogfmtFormat()) )
Functions ¶
func Debug ¶
func Debug(msg string, ctx ...interface{})
Debug is a convenient alias for Root().Debug
func Error ¶
func Error(msg string, ctx ...interface{})
Error is a convenient alias for Root().Error
func PrintOrigins ¶
func PrintOrigins(print bool)
PrintOrigins sets or unsets log location (file:line) printing for terminal format output.
Types ¶
type Ctx ¶
type Ctx map[string]interface{}
Ctx is a map of key/value pairs to pass as context to a log function Use this only if you really need greater safety around the arguments you pass to the logging functions.
type Format ¶
func FormatFunc ¶
FormatFunc returns a new Format object which uses the given function to perform record formatting.
func JsonFormat ¶
func JsonFormat() Format
JsonFormat formats log records as JSON objects separated by newlines. It is the equivalent of JsonFormatEx(false, true).
func JsonFormatEx ¶
JsonFormatEx formats log records as JSON objects. If pretty is true, records will be pretty-printed. If lineSeparated is true, records will be logged with a new line between each record.
func LogfmtFormat ¶
func LogfmtFormat() Format
LogfmtFormat prints records in logfmt format, an easy machine-parseable but human-readable format for key/value pairs.
For more details see: http://godoc.org/github.com/kr/logfmt
func TerminalFormat ¶
TerminalFormat formats log records optimized for human readability on a terminal with color-coded level output and terser human friendly timestamp. This format should only be used for interactive programs or while developing.
[TIME] [LEVEL] MESAGE key=value key=value ...
Example:
[May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
type GlogHandler ¶
type GlogHandler struct {
// contains filtered or unexported fields
}
func NewGlogHandler ¶
func NewGlogHandler(h Handler) *GlogHandler
NewGlogHandler creates a new log handler with filtering functionality similar to Google's glog logger. The returned handler implements Handler.
func (*GlogHandler) BacktraceAt ¶
func (h *GlogHandler) BacktraceAt(location string) error
func (*GlogHandler) Log ¶
func (h *GlogHandler) Log(r *Record) error
func (*GlogHandler) Verbosity ¶
func (h *GlogHandler) Verbosity(level Lvl)
func (*GlogHandler) Vmodule ¶
func (h *GlogHandler) Vmodule(ruleset string) error
type Handler ¶
A Logger prints its log records by writing to a Handler. The Handler interface defines where and how log records are written. Handlers are composable, providing you great flexibility in combining them to achieve the logging structure that suits your applications.
func DiscardHandler ¶
func DiscardHandler() Handler
DiscardHandler reports success for all writes but does nothing. It is useful for dynamically disabling logging at runtime via a Logger's SetHandler method.
func FuncHandler ¶
FuncHandler returns a Handler that logs records with the given function.
func LazyHandler ¶
LazyHandler writes all values to the wrapped handler after evaluating any lazy functions in the record's context. It is already wrapped around StreamHandler and SyslogHandler in this library, you'll only need it if you write your own Handler.
func StreamHandler ¶
StreamHandler wraps itself with LazyHandler and SyncHandler to evaluate Lazy objects and perform safe concurrent writes.
func SyncHandler ¶
SyncHandler can be wrapped around a handler to guarantee that only a single Log operation can proceed at a time. It's necessary for thread-safe concurrent writes.
type Logger ¶
type Logger interface {
// New returns a new Logger that has this logger's context plus the given context
New(ctx ...interface{}) Logger
// GetHandler gets the handler associated with the logger.
GetHandler() Handler
// SetHandler updates the logger to write records to the specified handler.
SetHandler(h Handler)
// Log a message at the given level with context key/value pairs
Trace(msg string, ctx ...interface{})
Debug(msg string, ctx ...interface{})
Info(msg string, ctx ...interface{})
Warn(msg string, ctx ...interface{})
Error(msg string, ctx ...interface{})
Crit(msg string, ctx ...interface{})
}
A Logger writes key/value pairs to a Handler
type Lvl ¶
type Lvl int
func (Lvl) AlignedString ¶
Aligned returns a 5-character string containing the name of a Lvl.
type Record ¶
type Record struct {
Time time.Time
Lvl Lvl
Msg string
Ctx []interface{}
Call stack.Call
KeyNames RecordKeyNames
}
A Record is what a Logger asks its handler to write
type RecordKeyNames ¶
type TerminalStringer ¶
type TerminalStringer interface {
TerminalString() string
}
TerminalStringer is an analogous interface to the stdlib stringer, allowing own types to have custom shortened serialization formats when printed to the screen.