Documentation ¶
Overview ¶
Package log provides an opiniated logging facility as it provides only 4 log levels.
Index ¶
- type BufferWriter
- type Event
- func (e *Event) Debug() Logger
- func (e *Event) Error() Logger
- func (e *Event) Info() Logger
- func (e *Event) Log(format string, args ...interface{})
- func (e *Event) Warn() Logger
- func (e *Event) WithComponent(component string) Logger
- func (e *Event) WithError(err error) Logger
- func (e *Event) WithField(key string, value interface{}) Logger
- func (e *Event) WithFields(f Fields) Logger
- func (e *Event) WithOutput(w Writer) Logger
- func (l *Event) Write(p []byte) (int, error)
- type Eventx
- type Fields
- type Formatter
- type Level
- type LevelRewriteRule
- type Logger
- type Writer
- func NewConsoleWriter(w io.Writer, level Level, useColor bool) Writer
- func NewJSONWriter(w io.Writer, level Level) Writer
- func NewLevelRewriter(writer Writer, rules []LevelRewriteRule) Writer
- func NewMultiWriter(writer ...Writer) Writer
- func NewSyncWriter(writer Writer) Writer
- func NewTopicWriter(writer Writer, topics []string) Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferWriter ¶
func NewBufferWriter ¶
func NewBufferWriter(level Level, lines int) BufferWriter
type Event ¶
type Event struct { Time time.Time Level Level Component string Caller string Message string Data Fields // contains filtered or unexported fields }
func (*Event) WithComponent ¶
func (*Event) WithFields ¶
func (*Event) WithOutput ¶
type Formatter ¶
func NewConsoleFormatter ¶
func NewJSONFormatter ¶
func NewJSONFormatter() Formatter
type LevelRewriteRule ¶
type Logger ¶
type Logger interface { // WithOutput adds an output to the Logger. The messages are written to the // provided writer if the log level of the message is more or equally critical // than level. Pass true for useColoe if colored output is desired. If the // writer doesn't support colored output, it will be automatically disabled. // The returned value implements the LoggerOutput interface which allows to // change the log level at any later point in time. WithOutput(w Writer) Logger // With returns a new Logger with the given context. The context may // printed along the message. This is up to the implementation. WithComponent(component string) Logger WithField(key string, value interface{}) Logger WithFields(fields Fields) Logger WithError(err error) Logger Log(format string, args ...interface{}) // Debug writes a message with the debug log level to all registered outputs. // The message will be written according to fmt.Printf(). The detail field will // be reset to nil. Debug() Logger // Info writes a message with the info log level to all registered outputs. // The message will be written according to fmt.Printf(). The detail field will // be reset to nil. Info() Logger // Warn writes a message with the warn log level to all registered outputs. // The message will be written according to fmt.Printf(). The detail field will // be reset to nil. Warn() Logger // Error writes a message with the error log level to all registered outputs. // The message will be written according to fmt.Printf(). The detail field will // be reset to nil. Error() Logger // Write implements the io.Writer interface such that it can be used in e.g. the // the log/Logger facility. Messages will be printed with debug level. Write(p []byte) (int, error) }
Logger is an interface that provides means for writing log messages.
There are 4 log levels available (debug, info, warn, error) with increasing severity. A message will be written to an output if the log level of the message has the same or a higher severity than the output. Otherwise it will be discarded.
Different outputs should be added with the AddOutput function.
The context is a string that represents who wrote the message.
type Writer ¶
func NewLevelRewriter ¶
func NewLevelRewriter(writer Writer, rules []LevelRewriteRule) Writer
func NewMultiWriter ¶
func NewSyncWriter ¶
func NewTopicWriter ¶
Click to show internal directories.
Click to hide internal directories.