From 94145fb4c7ebae1d604a1c71dd154ff4c08e5542 Mon Sep 17 00:00:00 2001 From: brent s Date: Sun, 13 Mar 2022 13:34:24 -0400 Subject: [PATCH] Add NullLogger to MultiLogger. --- logging/funcs_multilogger_mgr.go | 40 +++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/logging/funcs_multilogger_mgr.go b/logging/funcs_multilogger_mgr.go index dfdc5bf..1c26870 100644 --- a/logging/funcs_multilogger_mgr.go +++ b/logging/funcs_multilogger_mgr.go @@ -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) {