logger: refactor interface
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
dd8894e673
commit
622490fbf3
@ -39,6 +39,13 @@ func (l *defaultLogger) String() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func (l *defaultLogger) V(level Level) bool {
|
||||
if l.opts.Level.Enabled(level) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Fields(fields map[string]interface{}) Logger {
|
||||
l.Lock()
|
||||
l.opts.Fields = copyFields(fields)
|
||||
@ -79,8 +86,7 @@ func logCallerfilePath(loggingFilePath string) string {
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||
// TODO decide does we need to write message if log level not used?
|
||||
if !l.opts.Level.Enabled(level) {
|
||||
if !l.V(level) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -118,8 +124,7 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
|
||||
// TODO decide does we need to write message if log level not used?
|
||||
if level < l.opts.Level {
|
||||
if !l.V(level) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ var (
|
||||
type Logger interface {
|
||||
// Init initialises options
|
||||
Init(options ...Option) error
|
||||
// V compare provided verbosity level with current log level
|
||||
V(level Level) bool
|
||||
// The Logger options
|
||||
Options() Options
|
||||
// Fields set fields to always be logged
|
||||
|
Loading…
Reference in New Issue
Block a user