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