* support unix daemon socket * refactor(logger): logger fields changed to map[string]interface{} * improvement(logger): adding string to Level Parser * improvement(logger): rename ParseLevel to GetLevel * refactor(logger): adding basic logger adding micro default logger, and refactor logger interface * refactor(logger): moved basic logger to top level package * refactor(logger): adding default logger
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
// Package log provides a log interface
|
|
package logger
|
|
|
|
var (
|
|
// Default logger
|
|
DefaultLogger Logger = NewLogger()
|
|
)
|
|
|
|
// Logger is a generic logging interface
|
|
type Logger interface {
|
|
// Init initialises options
|
|
Init(options ...Option) error
|
|
// The Logger options
|
|
Options() Options
|
|
// Error set `error` field to be logged
|
|
Error(err error) Logger
|
|
// 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 Error(err error) Logger {
|
|
return DefaultLogger.Error(err)
|
|
}
|
|
|
|
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 SetGlobalLevel(lvl Level) {
|
|
if err := Init(WithLevel(lvl)); err != nil {
|
|
print(err)
|
|
}
|
|
}
|
|
|
|
func String() string {
|
|
return DefaultLogger.String()
|
|
}
|