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