Documentation ¶
Index ¶
- Variables
- 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 SetHandler(h Handler)
- 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) WithDuration(d time.Duration) *Entry
- 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 Handler
- type HandlerFunc
- type Interface
- type Level
- 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) WithDuration(d time.Duration) *Entry
- func (l *Logger) WithError(err error) *Entry
- func (l *Logger) WithField(key string, value interface{}) *Entry
- func (l *Logger) WithFields(fields Fielder) *Entry
- type TextHandler
Constants ¶
This section is empty.
Variables ¶
var Colors = [...]int{
DebugLevel: gray,
InfoLevel: blue,
WarnLevel: yellow,
ErrorLevel: red,
FatalLevel: red,
}
Colors mapping.
var Default = NewText(os.Stderr)
Default handler outputting to stderr.
var ErrInvalidLevel = errors.New("invalid level")
ErrInvalidLevel is returned if the severity level is invalid.
var Now = time.Now
Now returns the current time.
var Strings = [...]string{
DebugLevel: "DEBUG",
InfoLevel: "INFO",
WarnLevel: "WARN",
ErrorLevel: "ERROR",
FatalLevel: "FATAL",
}
Strings mapping.
Functions ¶
func Fatalf ¶
func Fatalf(msg string, v ...interface{})
Fatalf level formatted message, followed by an exit.
func SetHandler ¶
func SetHandler(h Handler)
SetHandler sets the handler. This is not thread-safe. The default handler outputs to the stdlib log.
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 `json:"-"` Fields Fields `json:"fields"` Level Level `json:"level"` Timestamp time.Time `json:"timestamp"` Message string `json:"message"` // 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 WithDuration ¶
WithDuration returns a new entry with the "duration" field set to the given duration in milliseconds.
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 log level is error.
func (*Entry) Trace ¶
Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
func (*Entry) WithDuration ¶
WithDuration returns a new entry with the "duration" field set to the given duration in milliseconds.
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 Handler ¶
Handler is used to handle log events, outputting them to stdio or sending them to remote services. See the "handlers" directory for implementations.
It is left up to Handlers to implement thread-safety.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as log handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
type Interface ¶
type Interface interface { WithFields(Fielder) *Entry WithField(string, interface{}) *Entry WithDuration(time.Duration) *Entry WithError(error) *Entry Debug(string) Info(string) Warn(string) Error(string) Fatal(string) Debugf(string, ...interface{}) Infof(string, ...interface{}) Warnf(string, ...interface{}) Errorf(string, ...interface{}) Fatalf(string, ...interface{}) Trace(string) *Entry }
Interface represents the API of both Logger and Entry.
var Log Interface = &Logger{ Handler: HandlerFunc(handleStdLog), Level: InfoLevel, }
singletons ftw?
type Level ¶
type Level int
Level of severity.
Log levels.
func MustParseLevel ¶
MustParseLevel parses level string or panics.
func (*Level) UnmarshalJSON ¶
UnmarshalJSON implementation.
type Logger ¶
Logger represents a logger with configurable Level and Handler.
func (*Logger) Trace ¶
Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
func (*Logger) WithDuration ¶
WithDuration returns a new entry with the "duration" field set to the given duration in milliseconds.
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.
type TextHandler ¶
Handler implementation.
func (*TextHandler) HandleLog ¶
func (h *TextHandler) HandleLog(e *Entry) error
HandleLog implements Handler.