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-11-04 00:38:12 +03:00
|
|
|
DefaultLogger Logger = 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
|
2020-11-04 00:38:12 +03:00
|
|
|
// Info level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Info(args ...interface{})
|
2020-11-04 00:38:12 +03:00
|
|
|
// Trace level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Trace(args ...interface{})
|
2020-11-04 00:38:12 +03:00
|
|
|
// Debug level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Debug(args ...interface{})
|
2020-11-04 00:38:12 +03:00
|
|
|
// Warn level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Warn(args ...interface{})
|
2020-11-04 00:38:12 +03:00
|
|
|
// Error level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Error(args ...interface{})
|
2020-11-04 00:38:12 +03:00
|
|
|
// Fatal level message
|
2020-11-10 22:18:16 +03:00
|
|
|
Fatal(args ...interface{})
|
|
|
|
// Infof level message
|
|
|
|
Infof(msg string, args ...interface{})
|
|
|
|
// Tracef level message
|
|
|
|
Tracef(msg string, args ...interface{})
|
|
|
|
// Debug level message
|
|
|
|
Debugf(msg string, args ...interface{})
|
|
|
|
// Warn level message
|
|
|
|
Warnf(msg string, args ...interface{})
|
|
|
|
// Error level message
|
|
|
|
Errorf(msg string, args ...interface{})
|
|
|
|
// Fatal level message
|
|
|
|
Fatalf(msg string, args ...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-12-08 00:38:37 +03:00
|
|
|
// Info writes msg to default logger on info level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Info(args ...interface{}) {
|
|
|
|
DefaultLogger.Info(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Error writes msg to default logger on error level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Error(args ...interface{}) {
|
|
|
|
DefaultLogger.Error(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Debug writes msg to default logger on debug level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Debug(args ...interface{}) {
|
|
|
|
DefaultLogger.Debug(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Warn writes msg to default logger on warn level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Warn(args ...interface{}) {
|
|
|
|
DefaultLogger.Warn(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Trace writes msg to default logger on trace level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Trace(args ...interface{}) {
|
|
|
|
DefaultLogger.Trace(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Fatal writes msg to default logger on fatal level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Fatal(args ...interface{}) {
|
|
|
|
DefaultLogger.Fatal(args...)
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Infof writes formatted msg to default logger on info level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Infof(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Infof(msg, args...)
|
2020-02-21 10:57:59 +03:00
|
|
|
}
|
2020-02-07 00:35:46 +03:00
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Errorf writes formatted msg to default logger on error level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Errorf(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Errorf(msg, args...)
|
2020-11-04 00:38:12 +03:00
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Debugf writes formatted msg to default logger on debug level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Debugf(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Debugf(msg, args...)
|
2020-11-04 00:38:12 +03:00
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Warnf writes formatted msg to default logger on warn level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Warnf(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Warnf(msg, args...)
|
2020-02-07 00:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Tracef writes formatted msg to default logger on trace level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Tracef(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Tracef(msg, args...)
|
2020-02-21 10:57:59 +03:00
|
|
|
}
|
2020-02-07 00:35:46 +03:00
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// Fatalf writes formatted msg to default logger on fatal level
|
2020-11-10 22:18:16 +03:00
|
|
|
func Fatalf(msg string, args ...interface{}) {
|
|
|
|
DefaultLogger.Fatalf(msg, args...)
|
2020-02-07 00:35:46 +03:00
|
|
|
}
|
2020-02-15 21:19:28 +03:00
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// V returns true if passed level enabled in default logger
|
2020-11-04 00:38:12 +03:00
|
|
|
func V(level Level) bool {
|
|
|
|
return DefaultLogger.V(level)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initialize logger
|
|
|
|
func Init(opts ...Option) error {
|
|
|
|
return DefaultLogger.Init(opts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fields create logger with specific fields
|
|
|
|
func Fields(fields map[string]interface{}) Logger {
|
|
|
|
return DefaultLogger.Fields(fields)
|
2020-02-15 21:19:28 +03:00
|
|
|
}
|