move log level setting to option (#1222)

This commit is contained in:
Asim Aslam 2020-02-20 08:26:12 +00:00 committed by GitHub
parent c7eed618c2
commit 78df154a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -10,21 +10,16 @@ import (
type Logger interface { type Logger interface {
// Init initialises options // Init initialises options
Init(options ...Option) error Init(options ...Option) error
// Level returns the logging level // The Logger options
Level() Level Options() Options
// Log inserts a log entry. Arguments may be handled in the manner
// of fmt.Print, but the underlying logger may also decide to handle
// them differently.
Log(level Level, v ...interface{})
// Logf insets a log entry. Arguments are handled in the manner of
// fmt.Printf.
Logf(level Level, format string, v ...interface{})
// Fields set fields to always be logged
Fields(fields map[string]interface{}) Logger
// Error set `error` field to be logged // Error set `error` field to be logged
Error(err error) Logger Error(err error) Logger
// SetLevel updates the logging level. // Fields set fields to always be logged
SetLevel(Level) 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 returns the name of logger
String() string String() string
} }

View File

@ -17,5 +17,15 @@ import (
type Option func(*Options) type Option func(*Options)
type Options struct { type Options struct {
// The Log Level
Level Level
// Other opts
Context context.Context Context context.Context
} }
// WithLevel sets the log level
func WithLevel(l Level) Option {
return func(o *Options) {
o.Level = l
}
}