|
@ -17,7 +17,8 @@ func NewFilter(next Logger, options ...Option) Logger { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// NewFilterByLevel wraps next and implements filtering based on a given level.
|
|
|
// NewFilterByLevel wraps next and implements filtering based on a given level.
|
|
|
func NewFilterByLevel(next Logger, lvl string) Logger { |
|
|
|
|
|
|
|
|
// Error is returned if level is not info, error or debug.
|
|
|
|
|
|
func NewFilterByLevel(next Logger, lvl string) (Logger, error) { |
|
|
var option Option |
|
|
var option Option |
|
|
switch lvl { |
|
|
switch lvl { |
|
|
case "info": |
|
|
case "info": |
|
@ -27,9 +28,9 @@ func NewFilterByLevel(next Logger, lvl string) Logger { |
|
|
case "error": |
|
|
case "error": |
|
|
option = AllowError() |
|
|
option = AllowError() |
|
|
default: |
|
|
default: |
|
|
panic(fmt.Sprintf("Expected either \"info\", \"debug\" or \"error\" log level, given %v", lvl)) |
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("Expected either \"info\", \"debug\" or \"error\" log level, given %v", lvl) |
|
|
} |
|
|
} |
|
|
return NewFilter(next, option) |
|
|
|
|
|
|
|
|
return NewFilter(next, option), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type filter struct { |
|
|
type filter struct { |
|
|