Add SetLevel function
This commit is contained in:
parent
d5add47d25
commit
ed50ff00ef
7
cli.go
7
cli.go
@ -14,6 +14,8 @@ import (
|
||||
"github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
var _ Logger = (*CLILogger)(nil)
|
||||
|
||||
type CLILogger struct {
|
||||
Out io.Writer
|
||||
Level LogLevel
|
||||
@ -66,6 +68,11 @@ func (pl *CLILogger) NoExit() {
|
||||
pl.noExit = true
|
||||
}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func (pl *CLILogger) SetLevel(l LogLevel) {
|
||||
pl.Level = l
|
||||
}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func (pl *CLILogger) Debug(msg string) LogBuilder {
|
||||
return newCLILogBuilder(pl, msg, LogLevelDebug)
|
||||
|
5
json.go
5
json.go
@ -40,6 +40,11 @@ func (jl *JSONLogger) NoExit() {
|
||||
jl.noExit = true
|
||||
}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func (jl *JSONLogger) SetLevel(l LogLevel) {
|
||||
jl.Level = l
|
||||
}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func (jl *JSONLogger) Debug(msg string) LogBuilder {
|
||||
return newJSONLogBuilder(jl, msg, LogLevelDebug)
|
||||
|
@ -1,8 +1,9 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"go.arsenm.dev/logger"
|
||||
"os"
|
||||
|
||||
"go.arsenm.dev/logger"
|
||||
)
|
||||
|
||||
var Logger logger.Logger = logger.NewJSON(os.Stderr)
|
||||
@ -17,6 +18,11 @@ func NoExit() {
|
||||
Logger.NoExit()
|
||||
}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func SetLevel(l logger.LogLevel) {
|
||||
Logger.SetLevel(l)
|
||||
}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func Debug(msg string) logger.LogBuilder {
|
||||
return Logger.Debug(msg)
|
||||
|
@ -1,8 +1,8 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -51,6 +51,9 @@ type Logger interface {
|
||||
// NoExit prevents the logger from exiting on fatal events
|
||||
NoExit()
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
SetLevel(LogLevel)
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
Debug(string) LogBuilder
|
||||
|
7
multi.go
7
multi.go
@ -34,6 +34,13 @@ func (ml *MultiLogger) NoPanic() {
|
||||
ml.noPanic = true
|
||||
}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func (ml *MultiLogger) SetLevel(l LogLevel) {
|
||||
for _, logger := range ml.Loggers {
|
||||
logger.SetLevel(l)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func (ml *MultiLogger) Debug(msg string) LogBuilder {
|
||||
lbs := make([]LogBuilder, len(ml.Loggers))
|
||||
|
3
nop.go
3
nop.go
@ -21,6 +21,9 @@ func (nl NopLogger) NoPanic() {}
|
||||
// NoExit prevents the logger from exiting on fatal events
|
||||
func (nl NopLogger) NoExit() {}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func (nl NopLogger) SetLevel(LogLevel) {}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func (nl NopLogger) Debug(msg string) LogBuilder {
|
||||
return NopLogBuilder{}
|
||||
|
@ -81,6 +81,11 @@ func (pl *PrettyLogger) NoExit() {
|
||||
pl.noExit = true
|
||||
}
|
||||
|
||||
// SetLevel sets the log level of the logger
|
||||
func (pl *PrettyLogger) SetLevel(l LogLevel) {
|
||||
pl.Level = l
|
||||
}
|
||||
|
||||
// Debug creates a new debug event with the given message
|
||||
func (pl *PrettyLogger) Debug(msg string) LogBuilder {
|
||||
return newPrettyLogBuilder(pl, msg, LogLevelDebug)
|
||||
|
Reference in New Issue
Block a user