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() { var wg sync.WaitGroup for _, l := range m.Loggers { wg.Add(1) go func() { defer wg.Done() l.Setup() }() } wg.Wait() } // Shutdown cleanly shuts down a MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) Shutdown() { var wg sync.WaitGroup for _, l := range m.Loggers { wg.Add(1) go func() { defer wg.Done() l.Shutdown() }() } wg.Wait() } // GetPrefix returns the prefix used by this MultiLogger (and all its MultiLogger.Loggers). func (m *MultiLogger) GetPrefix() string { return m.Prefix } /* 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) { var wg sync.WaitGroup m.EnableDebug = d for _, l := range m.Loggers { wg.Add(1) go func() { defer wg.Done() l.DoDebug(d) }() } wg.Wait() } /* 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) { var wg sync.WaitGroup m.Prefix = prefix for _, l := range m.Loggers { wg.Add(1) go func() { defer wg.Done() l.SetPrefix(prefix) }() } wg.Wait() } // 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{}) { if err = logObj.Alert(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Crit(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Debug(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Emerg(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Err(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Info(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Notice(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() 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{}) { if err = logObj.Warning(msg, rplc...); err != nil { e.AddError(err) err = nil } }(l, s, v) } wg.Wait() err = e return }