func main() { flag.Parse() log.SetHandler(text.New(os.Stderr)) log.SetLevel(log.DebugLevel) // set up producer svc := kinesis.New(session.New()) p := producer.New(producer.Config{ StreamName: *stream, BacklogSize: 500, Client: svc, }) p.Start() // open data file f, err := os.Open("/tmp/users.txt") if err != nil { log.Fatal("Cannot open users.txt file") } defer f.Close() // loop over file data b := bufio.NewScanner(f) for b.Scan() { err := p.Put(b.Bytes(), "site") if err != nil { log.WithError(err).Fatal("error producing") } } p.Stop() }
func init() { l := &log.Logger{ Handler: text.New(os.Stderr), Level: log.InfoLevel, } logger = log.NewEntry(l) }
func main() { log.SetHandler(text.New(os.Stderr)) ctx := log.WithFields(log.Fields{ "app": "myapp", "env": "prod", }) for range time.Tick(time.Second) { _ = work(ctx) } }
func hookBefore(c *cli.Context) error { level := log.InfoLevel syslogLevel := syslog.LOG_INFO if c.Bool("verbose") { level = log.DebugLevel syslogLevel = syslog.LOG_DEBUG } log.SetLevel(level) log.SetHandler(text.New(os.Stderr)) if c.String("syslog-server") != "" { server := strings.Split(c.String("syslog-server"), "://") if server[0] == "unix" { log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New("", "", syslogLevel, ""))) } else { if len(server) != 2 { log.Fatal("invalid syslog parameter") } log.SetHandler(multi.New(text.New(os.Stderr), sysloghandler.New(server[0], server[1], syslogLevel, ""))) } } return nil }
func TestServer_CheckConfig(t *testing.T) { log.SetHandler(text.New(os.Stderr)) Convey("Testing Server.CheckConfig", t, FailureContinues, func() { // FIXME: check with a script server, err := NewServer() So(err, ShouldBeNil) server.AllowedImages = []string{"alpine", "ubuntu:trusty", "abcde123"} So(server.CheckConfig(&ClientConfig{ImageName: "alpine"}), ShouldBeNil) So(server.CheckConfig(&ClientConfig{ImageName: "ubuntu:trusty"}), ShouldBeNil) So(server.CheckConfig(&ClientConfig{ImageName: "abcde123"}), ShouldBeNil) So(server.CheckConfig(&ClientConfig{ImageName: "abcde124"}), ShouldNotBeNil) So(server.CheckConfig(&ClientConfig{ImageName: "ubuntu:vivid"}), ShouldNotBeNil) }) }
func main() { log.SetHandler(text.New(os.Stderr)) ctx := log.WithFields(log.Fields{ "file": "something.png", "type": "image/png", "user": "******", }) for range time.Tick(time.Millisecond * 200) { ctx.Info("upload") ctx.Info("upload complete") ctx.Warn("upload retry") ctx.WithError(errors.New("unauthorized")).Error("upload failed") ctx.Errorf("failed to upload %s", "img.png") } }
func main() { log.SetHandler(multi.New( text.New(os.Stderr), kinesis.New("logs"), )) ctx := log.WithFields(log.Fields{ "file": "something.png", "type": "image/png", "user": "******", }) for range time.Tick(time.Millisecond * 100) { ctx.Info("upload") ctx.Info("upload complete") } }
func main() { flag.Parse() if *cfgAddr == "" { fmt.Println("required flag not provided: --config-http-address") os.Exit(1) } if *dnsAddr == "" { fmt.Println("required flag not provided: --lookupd-dns-address") os.Exit(1) } log.SetHandler(text.New(os.Stderr)) ctx := log.WithFields(log.Fields{ "cfgAddr": *cfgAddr, "dnsAddr": *dnsAddr, "ldPort": *ldPort, }) ips, err := dnscfg.Get(dnsAddr, ldPort) if err != nil { ctx.WithError(err).Error("dns lookup") os.Exit(1) } if len(ips) == 0 { ctx.Error("no ip addresses found") os.Exit(1) } cfgURL := "http://" + *cfgAddr + "/config/nsqlookupd_tcp_addresses" err = httpcfg.Set(cfgURL, ips) if err != nil { ctx.WithError(err).Error("setting config") } else { ctx.WithField("ips", ips).Info("setting config") } go configLoop(ctx, cfgURL) http.ListenAndServe(":6060", nil) }
func main() { log.SetHandler(text.New(os.Stderr)) log.SetLevel(log.DebugLevel) var ( app = flag.String("a", "", "App name") bucket = flag.String("b", "", "Bucket name") stream = flag.String("s", "", "Stream name") ) flag.Parse() e := &s3.Emitter{ Bucket: *bucket, Region: "us-west-1", } c := connector.NewConsumer(connector.Config{ AppName: *app, StreamName: *stream, }) c.Start(connector.HandlerFunc(func(b connector.Buffer) { body := new(bytes.Buffer) for _, r := range b.GetRecords() { body.Write(r.Data) } err := e.Emit( s3.Key("", b.FirstSeq(), b.LastSeq()), bytes.NewReader(body.Bytes()), ) if err != nil { fmt.Printf("error %s\n", err) os.Exit(1) } })) select {} // run forever }
func init() { //Default to console logging apexlog.SetHandler(cli.Default) //Upgrade to ElasticSearch if defined in ENV if os.Getenv("ES_ADDR") != "" { esClient := elastic.New(os.Getenv("ES_ADDR")) //"http://192.168.99.101:9200" esClient.HTTPClient = &http.Client{ Timeout: 5 * time.Second, } e := es.New(&es.Config{ Client: esClient, BufferSize: 100, }) t := text.New(os.Stderr) apexlog.SetHandler(multi.New(e, t)) } }
func main() { esClient := elastic.New("http://192.168.99.101:9200") esClient.HTTPClient = &http.Client{ Timeout: 5 * time.Second, } e := es.New(&es.Config{ Client: esClient, BufferSize: 100, }) t := text.New(os.Stderr) log.SetHandler(multi.New(e, t)) ctx := log.WithFields(log.Fields{ "file": "something.png", "type": "image/png", "user": "******", }) go func() { for range time.Tick(time.Millisecond * 200) { ctx.Info("upload") ctx.Info("upload complete") ctx.Warn("upload retry") ctx.WithError(errors.New("unauthorized")).Error("upload failed") ctx.Errorf("failed to upload %s", "img.png") } }() go func() { for range time.Tick(time.Millisecond * 25) { ctx.Info("upload") } }() select {} }
func main() { flag.Parse() log.SetHandler(text.New(os.Stderr)) if *verbose { log.SetLevel(log.DebugLevel) } else { log.SetLevel(log.InfoLevel) } if _, err := os.Stat(tpl); os.IsNotExist(err) { log.WithError(err).Fatal("template provided does not exist") } ctx := log.WithFields(log.Fields{ "app": "spacegophers", }) s := NewServer(ctx, *addr, tpl) // serve the server s.Serve() }
import ( "os" "time" . "github.com/onsi/ginkgo" // . "github.com/onsi/gomega" "github.com/apex/log" "github.com/apex/log/handlers/text" "github.com/joho/godotenv" ) var _ = Describe("Motivewave", func() { log.SetHandler(text.New(os.Stdout)) log.SetLevel(log.InfoLevel) godotenv.Load() path := os.Getenv("PATH_MWML") Describe("Selectors", func() { log.SetLevel(log.InfoLevel) mw := &mwQuery{} _ = mw.importMotiveWaveXML(path) markup, _ := mw.parse() It("Ongoing", func() { price := &Point{T: time.Now()}