logger
parent
e690f00e18
commit
36a701420c
|
@ -10,14 +10,14 @@ type internalLogger struct {
|
||||||
|
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
|
|
||||||
canNotLogDebug bool
|
mutedDebug bool
|
||||||
canNotLogError bool
|
mutedError bool
|
||||||
canNotLogFatal bool
|
mutedFatal bool
|
||||||
canNotLogHighlight bool
|
mutedHighlight bool
|
||||||
canNotLogInform bool
|
mutedInform bool
|
||||||
canNotLogPanic bool
|
mutedPanic bool
|
||||||
canNotLogTrace bool
|
mutedTrace bool
|
||||||
canNotLogWarn bool
|
mutedWarn bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogger(writer io.Writer, parameters ...string) Logger {
|
func NewLogger(writer io.Writer, parameters ...string) Logger {
|
||||||
|
@ -34,5 +34,5 @@ func NewLogger(writer io.Writer, parameters ...string) Logger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return logger
|
return &logger
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogDebug() bool {
|
func (receiver internalLogger) CanLogDebug() bool {
|
||||||
return !receiver.canNotLogDebug
|
return !receiver.mutedDebug
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Debug(a ...interface{}) {
|
func (receiver internalLogger) Debug(a ...interface{}) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogError() bool {
|
func (receiver internalLogger) CanLogError() bool {
|
||||||
return !receiver.canNotLogError
|
return !receiver.mutedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Error(a ...interface{}) error {
|
func (receiver internalLogger) Error(a ...interface{}) error {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogFatal() bool {
|
func (receiver internalLogger) CanLogFatal() bool {
|
||||||
return !receiver.canNotLogFatal
|
return !receiver.mutedFatal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Fatal(a ...interface{}) {
|
func (receiver internalLogger) Fatal(a ...interface{}) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogHighlight() bool {
|
func (receiver internalLogger) CanLogHighlight() bool {
|
||||||
return !receiver.canNotLogHighlight
|
return !receiver.mutedHighlight
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Highlight(a ...interface{}) {
|
func (receiver internalLogger) Highlight(a ...interface{}) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogInform() bool {
|
func (receiver internalLogger) CanLogInform() bool {
|
||||||
return !receiver.canNotLogInform
|
return !receiver.mutedInform
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Inform(a ...interface{}) {
|
func (receiver internalLogger) Inform(a ...interface{}) {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package flog
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteDebug() {
|
||||||
|
receiver.mutedDebug = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteError() {
|
||||||
|
receiver.mutedError = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteFatal() {
|
||||||
|
receiver.mutedFatal = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteHighlight() {
|
||||||
|
receiver.mutedHighlight = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteInform() {
|
||||||
|
receiver.mutedInform = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MutePanic() {
|
||||||
|
receiver.mutedPanic = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteTrace() {
|
||||||
|
receiver.mutedTrace = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (receiver *internalLogger) MuteWarn() {
|
||||||
|
receiver.mutedWarn = true
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogPanic() bool {
|
func (receiver internalLogger) CanLogPanic() bool {
|
||||||
return !receiver.canNotLogPanic
|
return !receiver.mutedPanic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Panic(a ...interface{}) {
|
func (receiver internalLogger) Panic(a ...interface{}) {
|
||||||
|
|
|
@ -19,5 +19,5 @@ func (receiver internalLogger) Prefix(newprefix ...string) Logger {
|
||||||
var logger internalLogger = receiver
|
var logger internalLogger = receiver
|
||||||
logger.prefix += prefix
|
logger.prefix += prefix
|
||||||
|
|
||||||
return logger
|
return &logger
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func TestLoggerPrefix(t *testing.T) {
|
||||||
|
|
||||||
newLogger := logger.Prefix(test.NewPrefix...)
|
newLogger := logger.Prefix(test.NewPrefix...)
|
||||||
|
|
||||||
newInternalLogger, casted := newLogger.(internalLogger)
|
newInternalLogger, casted := newLogger.(*internalLogger)
|
||||||
if !casted {
|
if !casted {
|
||||||
t.Errorf("For test #%d, could not cast to flog.internalLogger.", testNumber)
|
t.Errorf("For test #%d, could not cast to flog.internalLogger.", testNumber)
|
||||||
t.Logf("TYPE: %T", newLogger)
|
t.Logf("TYPE: %T", newLogger)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogTrace() bool {
|
func (receiver internalLogger) CanLogTrace() bool {
|
||||||
return !receiver.canNotLogTrace
|
return !receiver.mutedTrace
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Trace(a ...interface{}) {
|
func (receiver internalLogger) Trace(a ...interface{}) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (receiver internalLogger) CanLogWarn() bool {
|
func (receiver internalLogger) CanLogWarn() bool {
|
||||||
return !receiver.canNotLogWarn
|
return !receiver.mutedWarn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver internalLogger) Warn(a ...interface{}) {
|
func (receiver internalLogger) Warn(a ...interface{}) {
|
||||||
|
|
|
@ -4,34 +4,42 @@ type Logger interface {
|
||||||
CanLogDebug() bool
|
CanLogDebug() bool
|
||||||
Debug(...interface{})
|
Debug(...interface{})
|
||||||
Debugf(string, ...interface{})
|
Debugf(string, ...interface{})
|
||||||
|
MuteDebug()
|
||||||
|
|
||||||
CanLogError() bool
|
CanLogError() bool
|
||||||
Error(...interface{}) error
|
Error(...interface{}) error
|
||||||
Errorf(string, ...interface{}) error
|
Errorf(string, ...interface{}) error
|
||||||
|
MuteError()
|
||||||
|
|
||||||
CanLogFatal() bool
|
CanLogFatal() bool
|
||||||
Fatal(...interface{})
|
Fatal(...interface{})
|
||||||
Fatalf(string, ...interface{})
|
Fatalf(string, ...interface{})
|
||||||
|
MuteFatal()
|
||||||
|
|
||||||
CanLogHighlight() bool
|
CanLogHighlight() bool
|
||||||
Highlight(...interface{})
|
Highlight(...interface{})
|
||||||
Highlightf(string, ...interface{})
|
Highlightf(string, ...interface{})
|
||||||
|
MuteHighlight()
|
||||||
|
|
||||||
CanLogInform() bool
|
CanLogInform() bool
|
||||||
Inform(...interface{})
|
Inform(...interface{})
|
||||||
Informf(string, ...interface{})
|
Informf(string, ...interface{})
|
||||||
|
MuteInform()
|
||||||
|
|
||||||
CanLogPanic() bool
|
CanLogPanic() bool
|
||||||
Panic(...interface{})
|
Panic(...interface{})
|
||||||
Panicf(string, ...interface{})
|
Panicf(string, ...interface{})
|
||||||
|
MutePanic()
|
||||||
|
|
||||||
CanLogTrace() bool
|
CanLogTrace() bool
|
||||||
Trace(...interface{})
|
Trace(...interface{})
|
||||||
Tracef(string, ...interface{})
|
Tracef(string, ...interface{})
|
||||||
|
MuteTrace()
|
||||||
|
|
||||||
CanLogWarn() bool
|
CanLogWarn() bool
|
||||||
Warn(...interface{})
|
Warn(...interface{})
|
||||||
Warnf(string, ...interface{})
|
Warnf(string, ...interface{})
|
||||||
|
MuteWarn()
|
||||||
|
|
||||||
Prefix(...string) Logger
|
Prefix(...string) Logger
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
func TestInternalLoggerIsLogger(t *testing.T) {
|
func TestInternalLoggerIsLogger(t *testing.T) {
|
||||||
|
|
||||||
var x Logger = internalLogger{} // THIS IS WHAT ACTUALLY MATTERS.
|
var x Logger = &internalLogger{} // THIS IS WHAT ACTUALLY MATTERS.
|
||||||
|
|
||||||
if nil == x {
|
if nil == x {
|
||||||
t.Error("This should never happen.")
|
t.Error("This should never happen.")
|
||||||
|
|
Loading…
Reference in New Issue