package logging import ( `sync` `r00t2.io/goutils/multierr` ) // Setup sets up/configures a MultiLogger (and all its MultiLogger.Loggers) and prepares it for use. func (m *MultiLogger) Setup() (err error) { var wg sync.WaitGroup var errs *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func() { var err2 error defer wg.Done() if err2 = l.Setup(); err2 != nil { errs.AddError(err2) err2 = nil } }() } wg.Wait() if errs.Count() > 0 { err = errs return } return } // Shutdown cleanly shuts down a MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Shutdown() (err error) { var wg sync.WaitGroup var errs *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func() { var err2 error defer wg.Done() if err2 = l.Shutdown(); err2 != nil { errs.AddError(err2) err2 = nil } }() } wg.Wait() if errs.Count() > 0 { err = errs return } return } /* GetPrefix returns the prefix used by this MultiLogger (and all its MultiLogger.Loggers). err will always be nil; it's there for interface-compat. */ func (m *MultiLogger) GetPrefix() (prefix string, err error) { prefix = m.Prefix return } /* DoDebug sets the debug state of this MultiLogger (and all its MultiLogger.Loggers). Note that this merely acts as a *safety filter* for debug messages to avoid sensitive information being written to the log. If you had a logger-specific EnableDebug set, you will need to re-set it to your desired state after running this method. */ func (m *MultiLogger) DoDebug(d bool) (err error) { var wg sync.WaitGroup var errs *multierr.MultiError = multierr.NewMultiError(nil) m.EnableDebug = d for _, l := range m.Loggers { wg.Add(1) go func() { var err2 error defer wg.Done() if err2 = l.DoDebug(d); err2 != nil { errs.AddError(err2) err2 = nil } }() } wg.Wait() if errs.Count() > 0 { err = errs return } return } /* SetPrefix sets the prefix for this MultiLogger (and all its MultiLogger.Loggers). If you had a logger-specific Prefix set, you will need to re-set it to your desired prefix after running this method. */ func (m *MultiLogger) SetPrefix(prefix string) (err error) { var wg sync.WaitGroup var errs *multierr.MultiError = multierr.NewMultiError(nil) m.Prefix = prefix for _, l := range m.Loggers { wg.Add(1) go func() { var err2 error defer wg.Done() if err2 = l.SetPrefix(prefix); err != nil { errs.AddError(err2) err2 = nil } }() } wg.Wait() if errs.Count() > 0 { err = errs return } return } // Alert writes an ALERT-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Alert(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Alert(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Crit writes an CRITICAL-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Crit(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Crit(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Debug writes a DEBUG-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Debug(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Debug(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Emerg writes an EMERGENCY-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Emerg(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Emerg(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Err writes an ERROR-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Err(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Err(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Info writes an INFO-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Info(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Info(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Notice writes a NOTICE-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Notice(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Notice(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return } // Warning writes a WARNING/WARN-level message to this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Warning(s string, v ...interface{}) (err error) { var wg sync.WaitGroup var e *multierr.MultiError = multierr.NewMultiError(nil) for _, l := range m.Loggers { wg.Add(1) go func(logObj Logger, msg string, rplc ...interface{}) { defer wg.Done() if err = logObj.Warning(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v...) } wg.Wait() if !e.IsEmpty() { err = e } return }