package logging import ( `os` sysd `github.com/coreos/go-systemd/journal` `github.com/google/uuid` `r00t2.io/sysutils/paths` ) /* AddDefaultLogger adds a default Logger (as would be determined by GetLogger) to a MultiLogger. identifier is a string to use to identify the added Logger in MultiLogger.Loggers. If empty, one will be automatically generated. See the documentation for GetLogger for details on other arguments. */ func (m *MultiLogger) AddDefaultLogger(identifier string, logFlags int, logPaths ...string) (err error) { var l Logger var exists bool if identifier == "" { identifier = uuid.New().String() } if _, exists = m.Loggers[identifier]; exists { err = ErrExistingLogger return } if l, err = GetLogger(m.EnableDebug, m.Prefix, logFlags, logPaths...); err != nil { return } m.Loggers[identifier] = l return } /* AddSysdLogger adds a SystemDLogger to a MultiLogger. identifier is a string to use to identify the added SystemDLogger in MultiLogger.Loggers. If empty, one will be automatically generated. */ func (m *MultiLogger) AddSysdLogger(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 } if !sysd.Enabled() { err = ErrNoSysD return } m.Loggers[identifier] = &SystemDLogger{ EnableDebug: m.EnableDebug, Prefix: m.Prefix, } 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 } /* AddSyslogLogger adds a SyslogLogger to a MultiLogger. identifier is a string to use to identify the added SyslogLogger in MultiLogger.Loggers. If empty, one will be automatically generated. */ func (m *MultiLogger) AddSyslogLogger(identifier string) (err error) { var exists bool var hasSyslog bool var stat os.FileInfo var devlogPath string = devlog var prefix string if identifier == "" { identifier = uuid.New().String() } if _, exists = m.Loggers[identifier]; exists { err = ErrExistingLogger return } if hasSyslog, stat, err = paths.RealPathExistsStat(&devlogPath); hasSyslog && err != nil { return } else if !hasSyslog { err = ErrNoSyslog return } if stat.Mode().IsRegular() { err = ErrInvalidDevLog return } m.Loggers[identifier] = &SyslogLogger{ EnableDebug: m.EnableDebug, Prefix: m.Prefix, } 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 }