Add NullLogger to MultiLogger.
This commit is contained in:
parent
81a2d308f0
commit
94145fb4c7
@ -1,10 +1,10 @@
|
|||||||
package logging
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
`path`
|
"path"
|
||||||
|
|
||||||
`github.com/google/uuid`
|
"github.com/google/uuid"
|
||||||
`r00t2.io/sysutils/paths`
|
"r00t2.io/sysutils/paths"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -145,6 +145,40 @@ func (m *MultiLogger) AddFileLogger(identifier string, logFlags int, logfilePath
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
AddNullLogger adds a NullLogger to a MultiLogger.
|
||||||
|
|
||||||
|
identifier is a string to use to identify the added NullLogger in MultiLogger.Loggers.
|
||||||
|
If empty, one will be automatically generated.
|
||||||
|
*/
|
||||||
|
func (m *MultiLogger) AddNullLogger(identifier string) (err error) {
|
||||||
|
|
||||||
|
var exists bool
|
||||||
|
var prefix string
|
||||||
|
|
||||||
|
if identifier == "" {
|
||||||
|
identifier = uuid.New().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, exists = m.Loggers[identifier]; exists {
|
||||||
|
err = ErrExistingLogger
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Loggers[identifier] = &NullLogger{}
|
||||||
|
if err = m.Loggers[identifier].Setup(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if prefix, err = m.Loggers[identifier].GetPrefix(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Loggers[identifier].Debug("logger initialized of type %T with prefix %v", m.Loggers[identifier], prefix)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveLogger will let you remove a Logger from MultiLogger.Loggers.
|
// RemoveLogger will let you remove a Logger from MultiLogger.Loggers.
|
||||||
func (m *MultiLogger) RemoveLogger(identifier string) (err error) {
|
func (m *MultiLogger) RemoveLogger(identifier string) (err error) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user