// SetupLogging will initialize the logger backend and set the flags. func SetupLogging() { fmt := LogFormats[os.Getenv(envLoggingFmt)] if fmt == "" { fmt = LogFormats[defaultLogFormat] } backend := logging.NewLogBackend(os.Stderr, "", 0) logging.SetBackend(backend) logging.SetFormatter(logging.MustStringFormatter(fmt)) lvl := logging.ERROR if logenv := os.Getenv(envLogging); logenv != "" { var err error lvl, err = logging.LogLevel(logenv) if err != nil { } } SetAllLoggers(lvl) }
// Global writer group for logs to output to var WriterGroup = new(MirrorWriter) type Option func() // Configure applies the provided options sequentially from left to right func Configure(options ...Option) { for _, f := range options { f() } } // LdJSONFormatter Option formats the event log as line-delimited JSON var LdJSONFormatter = func() { logging.SetFormatter(&PoliteJSONFormatter{}) } // TextFormatter Option formats the event log as human-readable plain-text var TextFormatter = func() { logging.SetFormatter(logging.DefaultFormatter) } func Output(w io.Writer) Option { return func() { backend := logging.NewLogBackend(w, "", 0) logging.SetBackend(backend) // TODO return previous Output option } }