Documentation ¶
Index ¶
- Variables
- func AddReporter(r Reporter)
- func Debug(msg string)
- func Debugf(msg string, v ...interface{})
- func Error(msg string)
- func Errorf(msg string, v ...interface{})
- func Fatal(msg string)
- func Fatalf(msg string, v ...interface{})
- func Info(msg string)
- func Infof(msg string, v ...interface{})
- func SetLevel(l Level)
- func SetLevelFromString(s string)
- func Warn(msg string)
- func Warnf(msg string, v ...interface{})
- type Entry
- func (e *Entry) Debug(msg string)
- func (e *Entry) Debugf(msg string, v ...interface{})
- func (e *Entry) Error(msg string)
- func (e *Entry) Errorf(msg string, v ...interface{})
- func (e *Entry) Fatal(msg string)
- func (e *Entry) Fatalf(msg string, v ...interface{})
- func (e *Entry) Info(msg string)
- func (e *Entry) Infof(msg string, v ...interface{})
- func (e *Entry) Stop(err *error)
- func (e *Entry) Trace(msg string) *Entry
- func (e *Entry) Warn(msg string)
- func (e *Entry) Warnf(msg string, v ...interface{})
- func (e *Entry) WithError(err error) *Entry
- func (e *Entry) WithField(key string, value interface{}) *Entry
- func (e *Entry) WithFields(fields Fielder) *Entry
- type Fielder
- type Fields
- type Formatter
- type Level
- type LevelInfo
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(msg string, v ...interface{})
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(msg string, v ...interface{})
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(msg string, v ...interface{})
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(msg string, v ...interface{})
- func (l *Logger) Trace(msg string) *Entry
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(msg string, v ...interface{})
- func (l *Logger) WithError(err error) *Entry
- func (l *Logger) WithField(key string, value interface{}) *Entry
- func (l *Logger) WithFields(fields Fielder) *Entry
- func (l *Logger) Write(level Level, e *Entry, msg string, calldepth int) *Logger
- type Reporter
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultFormatter is the default formatter used and is only the message. DefaultFormatter = MustStringFormatter("{{ .Message }}") // FancyFormatter is the default formatter for fancy messages. FancyFormatter = MustStringFormatter(`[{{formatColorString "magentafg" (formatTime .Timestamp "2006-01-02 15:04:05")}}] {{formatColor .LevelColor .LevelTitle "\t>"}} {{ .Message }}`) )
var Levels = map[Level]LevelInfo{ FATAL: {Level: FATAL, Color: aurora.RedFg, Name: "Fatal"}, ERROR: {Level: ERROR, Color: aurora.RedFg, Name: "Error"}, WARN: {Level: WARN, Color: aurora.BrownFg, Name: "Warn"}, INFO: {Level: INFO, Color: aurora.CyanFg, Name: "Info"}, DEBUG: {Level: DEBUG, Color: aurora.MagentaFg, Name: "Debug"}, }
var Log = &Logger{ Reporters: []Reporter{stdLog{}}, Level: INFO, }
singletons ftw?
Functions ¶
func Fatalf ¶
func Fatalf(msg string, v ...interface{})
Fatalf level formatted message, followed by an exit.
func SetLevelFromString ¶
func SetLevelFromString(s string)
SetLevelFromString sets the log level from a string, panicing when invalid. This is not thread-safe.
Types ¶
type Entry ¶
type Entry struct { Logger *Logger Level Level Message string Formatted map[string]interface{} Fields Fields Timestamp time.Time // contains filtered or unexported fields }
Entry represents a single log entry.
func Trace ¶
Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
func WithFields ¶
WithFields returns a new entry with `fields` set.
func (*Entry) Stop ¶
Stop should be used with Trace, to fire off the completion message. When an `err` is passed the "error" field is set, and the write level is error.
func (*Entry) Trace ¶
Trace returns a new entry with a Stop method to fire off a corresponding completion write, useful with defer.
func (*Entry) WithError ¶
WithError returns a new entry with the "error" set to `err`.
The given error may implement .Fielder, if it does the method will add all its `.Fields()` into the returned entry.
func (*Entry) WithFields ¶
WithFields returns a new entry with `fields` set.
type Fielder ¶
type Fielder interface {
Fields() Fields
}
Fielder is an interface for providing fields to custom types.
type Fields ¶
type Fields map[string]interface{}
Fields represents a map of entry level data used for structured logging.
type Formatter ¶
type Formatter interface { Format(*Entry, int) map[string]interface{} Finalize(map[string]interface{}) (string, error) }
func MustStringFormatter ¶
MustStringFormatter is equivalent to NewStringFormatter with a call to panic on error.
func NewStringFormatter ¶
type Level ¶
type Level int
func GetLevelFromString ¶
GetLevelFromString returns the log level from a string, panicing when invalid
type Logger ¶
func (*Logger) Trace ¶
Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
func (*Logger) WithField ¶
WithField returns a new entry with the `key` and `value` set.
Note that the `key` should not have spaces in it - use camel case or underscores
func (*Logger) WithFields ¶
WithFields returns a new entry with `fields` set.