func main() { flag.Parse() // extract address from host flag addr, err := ma.NewMultiaddr(*host) if err != nil { log.WithField("err", err).Fatal("NewMultiaddr() failed") } p := addr.Protocols() if len(p) < 2 { log.WithField("addr", addr).Fatal("need two protocols in host flag (/ip/tcp)") } _, host, err := manet.DialArgs(addr) if err != nil { log.WithField("err", err).Fatal("manet.DialArgs() failed") } if *verbose { // lower log level log.SetLevel(log.DebugLevel) } // construct url to dial var u url.URL u.Scheme = "http" u.Host = host u.Path = *endpoint // show what we got start := time.Now() log.WithFields(log.Fields{ "when": start, "tries": *tries, "timeout": *timeout, "url": u.String(), }).Debug("starting") for *tries > 0 { f := log.Fields{"tries": *tries} err := checkOK(http.Get(u.String())) if err == nil { f["took"] = time.Since(start) log.WithFields(f).Println("status ok - endpoint reachable") os.Exit(0) } f["error"] = err log.WithFields(f).Debug("get failed") time.Sleep(*timeout) *tries-- } log.Println("failed.") os.Exit(1) }
var LdJSONFormatter = func() { logrus.SetFormatter(&PoliteJSONFormatter{}) } // TextFormatter Option formats the event log as human-readable plain-text var TextFormatter = func() { logrus.SetFormatter(&logrus.TextFormatter{}) } func Output(w io.Writer) Option { return func() { logrus.SetOutput(w) // TODO return previous Output option } } // LevelDebug Option sets the log level to debug var LevelDebug = func() { logrus.SetLevel(logrus.DebugLevel) } // LevelDebug Option sets the log level to error var LevelError = func() { logrus.SetLevel(logrus.ErrorLevel) } // LevelDebug Option sets the log level to info var LevelInfo = func() { logrus.SetLevel(logrus.InfoLevel) }