1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/logger/logger.go

54 lines
1.1 KiB
Go
Raw Normal View History

// Package log provides a log interface
package logger
var (
2022-09-30 16:27:07 +02:00
// Default logger.
DefaultLogger Logger = NewLogger()
2022-09-30 16:27:07 +02:00
// Default logger helper.
DefaultHelper *Helper = NewHelper(DefaultLogger)
)
2022-09-30 16:27:07 +02:00
// Logger is a generic logging interface.
type Logger interface {
2022-09-30 16:27:07 +02:00
// Init initializes 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{})
2020-02-06 23:36:33 +02: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()
}
func LoggerOrDefault(l Logger) Logger {
if l == nil {
return DefaultLogger
}
return l
}