micro/logger/logger.go

50 lines
1.1 KiB
Go
Raw Permalink Normal View History

// Package log provides a log interface
package logger
var (
// Default logger
DefaultLogger Logger = NewLogger()
)
// Logger is a generic logging interface
type Logger interface {
2020-02-07 00:36:33 +03:00
// Init initialises options
Init(options ...Option) error
// The Logger options
Options() Options
// Error set `error` field to be logged
Error(err error) Logger
// Fields set fields to always be logged
Fields(fields map[string]interface{}) Logger
// Log writes a log entry
Log(level Level, v ...interface{})
// Logf writes a formatted log entry
Logf(level Level, format string, v ...interface{})
2020-02-07 00:36:33 +03:00
// String returns the name of logger
String() string
}
func Init(opts ...Option) error {
return DefaultLogger.Init(opts...)
}
func Fields(fields map[string]interface{}) Logger {
return DefaultLogger.Fields(fields)
}
func Log(level Level, v ...interface{}) {
DefaultLogger.Log(level, v...)
}
func Logf(level Level, format string, v ...interface{}) {
DefaultLogger.Logf(level, format, v...)
}
func String() string {
return DefaultLogger.String()
}
2020-02-21 11:43:23 +03:00
func WithError(err error) Logger {
return DefaultLogger.Error(err)
}