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"
|
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 {
|
func (l *defaultLogger) Fields(fields map[string]interface{}) Logger {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
l.opts.Fields = copyFields(fields)
|
l.opts.Fields = copyFields(fields)
|
||||||
@ -79,8 +86,7 @@ func logCallerfilePath(loggingFilePath string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||||
// TODO decide does we need to write message if log level not used?
|
if !l.V(level) {
|
||||||
if !l.opts.Level.Enabled(level) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +124,7 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *defaultLogger) Logf(level Level, format string, 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 !l.V(level) {
|
||||||
if level < l.opts.Level {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ var (
|
|||||||
type Logger interface {
|
type Logger interface {
|
||||||
// Init initialises options
|
// Init initialises options
|
||||||
Init(options ...Option) error
|
Init(options ...Option) error
|
||||||
|
// V compare provided verbosity level with current log level
|
||||||
|
V(level Level) bool
|
||||||
// The Logger options
|
// The Logger options
|
||||||
Options() Options
|
Options() Options
|
||||||
// Fields set fields to always be logged
|
// Fields set fields to always be logged
|
||||||
|
Loading…
Reference in New Issue
Block a user