mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
1db36357d5
* feat(logger): add logger option to all components * fix: refactor api/rpc.go * fix: refactor api/stream.go * fix: api/options.go comment * fix(logger): do not use logger.Helper internally * fix(logger): fix comments * fix(logger): use level.Enabled method * fix: rename mlogger to log * fix: run go fmt * fix: log level * fix: factories Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com> Co-authored-by: Davincible <david.brouwer.99@gmail.com>
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Package log provides a log interface
|
|
package logger
|
|
|
|
var (
|
|
// Default logger
|
|
DefaultLogger Logger = NewLogger()
|
|
|
|
// Default logger helper
|
|
DefaultHelper *Helper = NewHelper(DefaultLogger)
|
|
)
|
|
|
|
// Logger is a generic logging interface
|
|
type Logger interface {
|
|
// Init initialises options
|
|
Init(options ...Option) error
|
|
// The Logger options
|
|
Options() Options
|
|
// 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{})
|
|
// 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()
|
|
}
|
|
|
|
func LoggerOrDefault(l Logger) Logger {
|
|
if l == nil {
|
|
return DefaultLogger
|
|
}
|
|
return l
|
|
}
|