logger: refactor interface

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-08-29 17:43:06 +03:00
parent dd8894e673
commit 622490fbf3
2 changed files with 11 additions and 4 deletions

View File

@ -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
}

View File

@ -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