2020-11-02 13:25:29 +03:00
|
|
|
// Package logger provides a log interface
|
2020-02-07 00:35:46 +03:00
|
|
|
package logger
|
|
|
|
|
2020-02-21 10:57:59 +03:00
|
|
|
var (
|
2020-11-02 13:25:29 +03:00
|
|
|
// DefaultLogger variable
|
2020-02-29 03:31:59 +03:00
|
|
|
DefaultLogger Logger = NewHelper(NewLogger())
|
2020-02-07 00:35:46 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Logger is a generic logging interface
|
|
|
|
type Logger interface {
|
2020-02-07 00:36:33 +03:00
|
|
|
// Init initialises options
|
2020-10-16 09:38:57 +03:00
|
|
|
Init(opts ...Option) error
|
2020-08-29 17:43:06 +03:00
|
|
|
// V compare provided verbosity level with current log level
|
|
|
|
V(level Level) bool
|
2020-02-20 11:26:12 +03: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-07 00:36:33 +03:00
|
|
|
// String returns the name of logger
|
|
|
|
String() string
|
2020-02-07 00:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// Init initialize logger
|
2020-02-21 10:57:59 +03:00
|
|
|
func Init(opts ...Option) error {
|
|
|
|
return DefaultLogger.Init(opts...)
|
|
|
|
}
|
2020-02-07 00:35:46 +03:00
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// Fields create logger with specific fields
|
2020-02-21 10:57:59 +03:00
|
|
|
func Fields(fields map[string]interface{}) Logger {
|
|
|
|
return DefaultLogger.Fields(fields)
|
2020-02-07 00:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// Log writes log with specific level
|
2020-02-21 10:57:59 +03:00
|
|
|
func Log(level Level, v ...interface{}) {
|
|
|
|
DefaultLogger.Log(level, v...)
|
|
|
|
}
|
2020-02-07 00:35:46 +03:00
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// Logf writes formatted log with specific level
|
2020-02-21 10:57:59 +03:00
|
|
|
func Logf(level Level, format string, v ...interface{}) {
|
|
|
|
DefaultLogger.Logf(level, format, v...)
|
2020-02-07 00:35:46 +03:00
|
|
|
}
|
2020-02-15 21:19:28 +03:00
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// String return logger name
|
2020-02-21 10:57:59 +03:00
|
|
|
func String() string {
|
|
|
|
return DefaultLogger.String()
|
2020-02-15 21:19:28 +03:00
|
|
|
}
|