2020-02-06 23:35:46 +02:00
|
|
|
// Package log provides a log interface
|
|
|
|
package logger
|
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
var (
|
2022-09-30 16:27:07 +02:00
|
|
|
// Default logger.
|
2021-09-19 11:40:09 +02:00
|
|
|
DefaultLogger Logger = NewLogger()
|
2022-09-29 16:44:53 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Default logger helper.
|
2022-09-29 16:44:53 +02:00
|
|
|
DefaultHelper *Helper = NewHelper(DefaultLogger)
|
2020-02-06 23:35:46 +02:00
|
|
|
)
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Logger is a generic logging interface.
|
2020-02-06 23:35:46 +02:00
|
|
|
type Logger interface {
|
2022-09-30 16:27:07 +02:00
|
|
|
// Init initializes options
|
2020-02-06 23:35:46 +02:00
|
|
|
Init(options ...Option) error
|
2020-02-20 10:26:12 +02:00
|
|
|
// 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
|
2020-02-06 23:35:46 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
func Init(opts ...Option) error {
|
|
|
|
return DefaultLogger.Init(opts...)
|
|
|
|
}
|
2020-02-06 23:35:46 +02:00
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
func Fields(fields map[string]interface{}) Logger {
|
|
|
|
return DefaultLogger.Fields(fields)
|
2020-02-06 23:35:46 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
func Log(level Level, v ...interface{}) {
|
|
|
|
DefaultLogger.Log(level, v...)
|
|
|
|
}
|
2020-02-06 23:35:46 +02:00
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
func Logf(level Level, format string, v ...interface{}) {
|
|
|
|
DefaultLogger.Logf(level, format, v...)
|
2020-02-06 23:35:46 +02:00
|
|
|
}
|
2020-02-15 20:19:28 +02:00
|
|
|
|
2020-02-21 09:57:59 +02:00
|
|
|
func String() string {
|
|
|
|
return DefaultLogger.String()
|
2020-02-15 20:19:28 +02:00
|
|
|
}
|
2022-09-29 16:44:53 +02:00
|
|
|
|
|
|
|
func LoggerOrDefault(l Logger) Logger {
|
|
|
|
if l == nil {
|
|
|
|
return DefaultLogger
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|