Add NullLogger to MultiLogger.

This commit is contained in:
brent s. 2022-03-13 13:34:24 -04:00
parent 81a2d308f0
commit 94145fb4c7
Signed by: bts
GPG Key ID: 8C004C2F93481F6B

View File

@ -1,10 +1,10 @@
package logging

import (
`path`
"path"

`github.com/google/uuid`
`r00t2.io/sysutils/paths`
"github.com/google/uuid"
"r00t2.io/sysutils/paths"
)

/*
@ -145,6 +145,40 @@ func (m *MultiLogger) AddFileLogger(identifier string, logFlags int, logfilePath
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.
func (m *MultiLogger) RemoveLogger(identifier string) (err error) {